add panel.onRederFinished to be invoked after shader.render make sure coordinatorPlugin affected

This commit is contained in:
pengfei.zhou
2020-03-10 18:51:53 +08:00
committed by osborn
parent 01d736c5a6
commit f3f28c55f8
17 changed files with 290 additions and 332 deletions

View File

@@ -19,6 +19,7 @@ import { List } from "../widget/list"
import { FlowLayout } from "../widget/flowlayout"
import { View } from "../ui/view"
import { Color } from "../util/color"
import { Panel } from "../ui/panel"
function viewIdChains(view: View) {
const viewIds = []
@@ -32,7 +33,7 @@ function viewIdChains(view: View) {
export function coordinator(context: BridgeContext) {
return {
verticalScrolling: async (
verticalScrolling: (
argument: {
scrollable: Scroller | List | FlowLayout,
scrollRange: {
@@ -46,18 +47,22 @@ export function coordinator(context: BridgeContext) {
end: number | Color
},
}) => {
await context.callNative("coordinator", "ready");
(argument as any).scrollable = viewIdChains(argument.scrollable)
if (argument.target instanceof View) {
(argument as any).target = viewIdChains(argument.target)
if (context.entity instanceof Panel) {
const panel = context.entity
panel.onRenderFinished = () => {
(argument as any).scrollable = viewIdChains(argument.scrollable)
if (argument.target instanceof View) {
(argument as any).target = viewIdChains(argument.target)
}
if (argument.changing.start instanceof Color) {
argument.changing.start = argument.changing.start.toModel()
}
if (argument.changing.end instanceof Color) {
argument.changing.end = argument.changing.end.toModel()
}
return context.callNative("coordinator", "verticalScrolling", argument)
}
}
if (argument.changing.start instanceof Color) {
argument.changing.start = argument.changing.start.toModel()
}
if (argument.changing.end instanceof Color) {
argument.changing.end = argument.changing.end.toModel()
}
return context.callNative("coordinator", "verticalScrolling", argument)
}
}
}

View File

@@ -45,6 +45,8 @@ export abstract class Panel {
private __root__ = new Root
private headviews: Map<string, Map<string, View>> = new Map
onRenderFinished?: () => void
addHeadView(type: string, v: View) {
let map = this.headviews.get(type)
if (map) {
@@ -157,7 +159,7 @@ export abstract class Panel {
}
private nativeRender(model: Model) {
this.context.callNative("shader", "render", model)
return this.context.callNative("shader", "render", model)
}
private hookBeforeNativeCall() {
@@ -172,18 +174,19 @@ export abstract class Panel {
}
private hookAfterNativeCall() {
const promises: Promise<any>[] = []
if (Environment.platform !== 'web') {
//Here insert a native call to ensure the promise is resolved done.
nativeEmpty()
if (this.__root__.isDirty()) {
const model = this.__root__.toModel()
this.nativeRender(model)
promises.push(this.nativeRender(model))
}
for (let map of this.headviews.values()) {
for (let v of map.values()) {
if (v.isDirty()) {
const model = v.toModel()
this.nativeRender(model)
promises.push(this.nativeRender(model))
}
}
}
@@ -191,19 +194,24 @@ export abstract class Panel {
Promise.resolve().then(() => {
if (this.__root__.isDirty()) {
const model = this.__root__.toModel()
this.nativeRender(model)
promises.push(this.nativeRender(model))
this.__root__.clean()
}
for (let map of this.headviews.values()) {
for (let v of map.values()) {
if (v.isDirty()) {
const model = v.toModel()
this.nativeRender(model)
promises.push(this.nativeRender(model))
v.clean()
}
}
}
})
}
Promise.all(promises).then(_ => {
if (this.onRenderFinished) {
this.onRenderFinished()
}
})
}
}