From 7c88eebeb86cffa95fc3cef8c84664ff34485aab Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Thu, 26 Dec 2019 11:23:56 +0800 Subject: [PATCH] js:adjust hook timing for nested situation --- .../doric/shader/slider/NestedSliderNode.java | 2 +- doric-demo/src/StickDemo.ts | 2 +- doric-js/bundle/doric-lib.js | 31 ++++++++++++++--- doric-js/bundle/doric-vm.js | 31 ++++++++++++++--- doric-js/src/ui/panel.ts | 34 +++++++++++++++---- 5 files changed, 81 insertions(+), 19 deletions(-) diff --git a/doric-android/doric/src/main/java/pub/doric/shader/slider/NestedSliderNode.java b/doric-android/doric/src/main/java/pub/doric/shader/slider/NestedSliderNode.java index 204164ef..e214bb05 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/slider/NestedSliderNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/slider/NestedSliderNode.java @@ -73,7 +73,7 @@ public class NestedSliderNode extends GroupNode implements ViewPager. @NotNull @Override public Object instantiateItem(@NotNull ViewGroup container, int position) { - container.addView(slideItems.get(position), 0); + container.addView(slideItems.get(position)); return slideItems.get(position); } }); diff --git a/doric-demo/src/StickDemo.ts b/doric-demo/src/StickDemo.ts index 37a85aad..be401584 100644 --- a/doric-demo/src/StickDemo.ts +++ b/doric-demo/src/StickDemo.ts @@ -77,7 +77,7 @@ class StickDemo extends Panel { return new FlowLayoutItem().apply({ backgroundColor: colors[itemIdx % colors.length], height: 50, - layoutConfig: layoutConfig().configWidth(LayoutSpec.JUST), + layoutConfig: layoutConfig().configWidth(LayoutSpec.MOST), }).also(it => { it.addChild(text({ text: `In Page ${idx},${itemIdx}`, diff --git a/doric-js/bundle/doric-lib.js b/doric-js/bundle/doric-lib.js index 3fcadcd7..e8bdadc6 100644 --- a/doric-js/bundle/doric-lib.js +++ b/doric-js/bundle/doric-lib.js @@ -736,23 +736,44 @@ class Panel { this.context.shader.render(model); } hookBeforeNativeCall() { + if (Environment.platform !== 'h5') { + this.__root__.clean(); + for (let v of this.headviews.values()) { + v.clean(); + } + } } hookAfterNativeCall() { - //Here insert a native call to ensure the promise is resolved done. - Promise.resolve().then(() => { + if (Environment.platform !== 'h5') { + //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); - this.__root__.clean(); } for (let v of this.headviews.values()) { if (v.isDirty()) { const model = v.toModel(); this.nativeRender(model); - v.clean(); } } - }); + } + else { + Promise.resolve().then(() => { + if (this.__root__.isDirty()) { + const model = this.__root__.toModel(); + this.nativeRender(model); + this.__root__.clean(); + } + for (let v of this.headviews.values()) { + if (v.isDirty()) { + const model = v.toModel(); + this.nativeRender(model); + v.clean(); + } + } + }); + } } } __decorate$2([ diff --git a/doric-js/bundle/doric-vm.js b/doric-js/bundle/doric-vm.js index d45430d3..5a532f19 100644 --- a/doric-js/bundle/doric-vm.js +++ b/doric-js/bundle/doric-vm.js @@ -2184,23 +2184,44 @@ class Panel { this.context.shader.render(model); } hookBeforeNativeCall() { + if (Environment.platform !== 'h5') { + this.__root__.clean(); + for (let v of this.headviews.values()) { + v.clean(); + } + } } hookAfterNativeCall() { - //Here insert a native call to ensure the promise is resolved done. - Promise.resolve().then(() => { + if (Environment.platform !== 'h5') { + //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); - this.__root__.clean(); } for (let v of this.headviews.values()) { if (v.isDirty()) { const model = v.toModel(); this.nativeRender(model); - v.clean(); } } - }); + } + else { + Promise.resolve().then(() => { + if (this.__root__.isDirty()) { + const model = this.__root__.toModel(); + this.nativeRender(model); + this.__root__.clean(); + } + for (let v of this.headviews.values()) { + if (v.isDirty()) { + const model = v.toModel(); + this.nativeRender(model); + v.clean(); + } + } + }); + } } } __decorate$2([ diff --git a/doric-js/src/ui/panel.ts b/doric-js/src/ui/panel.ts index 4dfa3176..4785b659 100644 --- a/doric-js/src/ui/panel.ts +++ b/doric-js/src/ui/panel.ts @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import '../runtime/global' import { View, Group } from "./view" import { loge } from '../util/log' import { Model } from '../util/types' @@ -31,6 +30,8 @@ export function NativeCall(target: Panel, propertyKey: string, descriptor: Prope type Frame = { width: number, height: number } +declare function nativeEmpty(): void + export abstract class Panel { context!: BridgeContext onCreate() { } @@ -141,24 +142,43 @@ export abstract class Panel { } private hookBeforeNativeCall() { + if (Environment.platform !== 'h5') { + this.__root__.clean() + for (let v of this.headviews.values()) { + v.clean() + } + } } private hookAfterNativeCall() { - //Here insert a native call to ensure the promise is resolved done. - Promise.resolve().then(() => { + if (Environment.platform !== 'h5') { + //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) - this.__root__.clean() } for (let v of this.headviews.values()) { if (v.isDirty()) { const model = v.toModel() this.nativeRender(model) - v.clean() } } - }) + } else { + Promise.resolve().then(() => { + if (this.__root__.isDirty()) { + const model = this.__root__.toModel() + this.nativeRender(model) + this.__root__.clean() + } + for (let v of this.headviews.values()) { + if (v.isDirty()) { + const model = v.toModel() + this.nativeRender(model) + v.clean() + } + } + }) + } } - } \ No newline at end of file