From 4b1fcc439d725abb98eb8873c3d55430fd621237 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Wed, 25 Dec 2019 14:37:14 +0800 Subject: [PATCH] feat:when in H5 environment,must set check dirty to next macro task loop incase the changing occured in promise.then function which is scheduled in micro task loop --- doric-js/bundle/doric-lib.js | 34 +++++++++++++++++++++--------- doric-js/bundle/doric-vm.js | 34 +++++++++++++++++++++--------- doric-js/src/runtime/global.ts | 2 +- doric-js/src/ui/panel.ts | 38 +++++++++++++++++++++++----------- 4 files changed, 75 insertions(+), 33 deletions(-) diff --git a/doric-js/bundle/doric-lib.js b/doric-js/bundle/doric-lib.js index e1f54658..4de47dee 100644 --- a/doric-js/bundle/doric-lib.js +++ b/doric-js/bundle/doric-lib.js @@ -733,9 +733,7 @@ class Panel { }, undefined); } nativeRender(model) { - if (this.context) { - this.context.shader.render(model); - } + this.context.shader.render(model); } hookBeforeNativeCall() { this.__root__.clean(); @@ -745,16 +743,32 @@ class Panel { } hookAfterNativeCall() { //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); + if (Environment.platform === 'h5') { + setTimeout(() => { + if (this.__root__.isDirty()) { + const model = this.__root__.toModel(); + this.nativeRender(model); + } + for (let v of this.headviews.values()) { + if (v.isDirty()) { + const model = v.toModel(); + this.nativeRender(model); + } + } + }, 0); } - for (let v of this.headviews.values()) { - if (v.isDirty()) { - const model = v.toModel(); + else { + nativeEmpty(); + if (this.__root__.isDirty()) { + const model = this.__root__.toModel(); this.nativeRender(model); } + for (let v of this.headviews.values()) { + if (v.isDirty()) { + const model = v.toModel(); + this.nativeRender(model); + } + } } } } diff --git a/doric-js/bundle/doric-vm.js b/doric-js/bundle/doric-vm.js index bd8a4450..ecb1a13d 100644 --- a/doric-js/bundle/doric-vm.js +++ b/doric-js/bundle/doric-vm.js @@ -2181,9 +2181,7 @@ class Panel { }, undefined); } nativeRender(model) { - if (this.context) { - this.context.shader.render(model); - } + this.context.shader.render(model); } hookBeforeNativeCall() { this.__root__.clean(); @@ -2193,16 +2191,32 @@ class Panel { } hookAfterNativeCall() { //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); + if (Environment.platform === 'h5') { + setTimeout(() => { + if (this.__root__.isDirty()) { + const model = this.__root__.toModel(); + this.nativeRender(model); + } + for (let v of this.headviews.values()) { + if (v.isDirty()) { + const model = v.toModel(); + this.nativeRender(model); + } + } + }, 0); } - for (let v of this.headviews.values()) { - if (v.isDirty()) { - const model = v.toModel(); + else { + nativeEmpty(); + if (this.__root__.isDirty()) { + const model = this.__root__.toModel(); this.nativeRender(model); } + for (let v of this.headviews.values()) { + if (v.isDirty()) { + const model = v.toModel(); + this.nativeRender(model); + } + } } } } diff --git a/doric-js/src/runtime/global.ts b/doric-js/src/runtime/global.ts index 356b1261..5ba6cdf4 100644 --- a/doric-js/src/runtime/global.ts +++ b/doric-js/src/runtime/global.ts @@ -20,7 +20,7 @@ export type BridgeContext = { [index: string]: { [index: string]: (args?: any) = declare global { const context: BridgeContext const Environment: { - platform: "Android" | "iOS" | "Qt", + platform: "Android" | "iOS" | "Qt" | "h5", platformVersion: string, diff --git a/doric-js/src/ui/panel.ts b/doric-js/src/ui/panel.ts index da919a1a..46a93041 100644 --- a/doric-js/src/ui/panel.ts +++ b/doric-js/src/ui/panel.ts @@ -18,6 +18,7 @@ import { View, Group } from "./view" import { loge } from '../util/log' import { Model } from '../util/types' import { Root } from '../widget/layouts' +import { BridgeContext } from '../runtime/global' export function NativeCall(target: Panel, propertyKey: string, descriptor: PropertyDescriptor) { @@ -34,7 +35,7 @@ type Frame = { width: number, height: number } declare function nativeEmpty(): void export abstract class Panel { - context?: any + context!: BridgeContext onCreate() { } onDestroy() { } onShow() { } @@ -139,9 +140,7 @@ export abstract class Panel { } private nativeRender(model: Model) { - if (this.context) { - this.context.shader.render(model) - } + this.context.shader.render(model) } private hookBeforeNativeCall() { @@ -153,16 +152,31 @@ export abstract class Panel { private hookAfterNativeCall() { //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) - } - for (let v of this.headviews.values()) { - if (v.isDirty()) { - const model = v.toModel() + if (Environment.platform === 'h5') { + setTimeout(() => { + if (this.__root__.isDirty()) { + const model = this.__root__.toModel() + this.nativeRender(model) + } + for (let v of this.headviews.values()) { + if (v.isDirty()) { + const model = v.toModel() + this.nativeRender(model) + } + } + }, 0) + } else { + nativeEmpty() + if (this.__root__.isDirty()) { + const model = this.__root__.toModel() this.nativeRender(model) } + for (let v of this.headviews.values()) { + if (v.isDirty()) { + const model = v.toModel() + this.nativeRender(model) + } + } } }