js:adjust hook timing for nested situation

This commit is contained in:
pengfei.zhou 2019-12-26 11:23:56 +08:00 committed by osborn
parent 48e6066e75
commit 7c88eebeb8
5 changed files with 81 additions and 19 deletions

View File

@ -73,7 +73,7 @@ public class NestedSliderNode extends GroupNode<ViewPager> implements ViewPager.
@NotNull @NotNull
@Override @Override
public Object instantiateItem(@NotNull ViewGroup container, int position) { public Object instantiateItem(@NotNull ViewGroup container, int position) {
container.addView(slideItems.get(position), 0); container.addView(slideItems.get(position));
return slideItems.get(position); return slideItems.get(position);
} }
}); });

View File

@ -77,7 +77,7 @@ class StickDemo extends Panel {
return new FlowLayoutItem().apply({ return new FlowLayoutItem().apply({
backgroundColor: colors[itemIdx % colors.length], backgroundColor: colors[itemIdx % colors.length],
height: 50, height: 50,
layoutConfig: layoutConfig().configWidth(LayoutSpec.JUST), layoutConfig: layoutConfig().configWidth(LayoutSpec.MOST),
}).also(it => { }).also(it => {
it.addChild(text({ it.addChild(text({
text: `In Page ${idx},${itemIdx}`, text: `In Page ${idx},${itemIdx}`,

View File

@ -736,23 +736,44 @@ class Panel {
this.context.shader.render(model); this.context.shader.render(model);
} }
hookBeforeNativeCall() { hookBeforeNativeCall() {
if (Environment.platform !== 'h5') {
this.__root__.clean();
for (let v of this.headviews.values()) {
v.clean();
}
}
} }
hookAfterNativeCall() { hookAfterNativeCall() {
//Here insert a native call to ensure the promise is resolved done. if (Environment.platform !== 'h5') {
Promise.resolve().then(() => { //Here insert a native call to ensure the promise is resolved done.
nativeEmpty();
if (this.__root__.isDirty()) { if (this.__root__.isDirty()) {
const model = this.__root__.toModel(); const model = this.__root__.toModel();
this.nativeRender(model); this.nativeRender(model);
this.__root__.clean();
} }
for (let v of this.headviews.values()) { for (let v of this.headviews.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel(); const model = v.toModel();
this.nativeRender(model); 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([ __decorate$2([

View File

@ -2184,23 +2184,44 @@ class Panel {
this.context.shader.render(model); this.context.shader.render(model);
} }
hookBeforeNativeCall() { hookBeforeNativeCall() {
if (Environment.platform !== 'h5') {
this.__root__.clean();
for (let v of this.headviews.values()) {
v.clean();
}
}
} }
hookAfterNativeCall() { hookAfterNativeCall() {
//Here insert a native call to ensure the promise is resolved done. if (Environment.platform !== 'h5') {
Promise.resolve().then(() => { //Here insert a native call to ensure the promise is resolved done.
nativeEmpty();
if (this.__root__.isDirty()) { if (this.__root__.isDirty()) {
const model = this.__root__.toModel(); const model = this.__root__.toModel();
this.nativeRender(model); this.nativeRender(model);
this.__root__.clean();
} }
for (let v of this.headviews.values()) { for (let v of this.headviews.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel(); const model = v.toModel();
this.nativeRender(model); 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([ __decorate$2([

View File

@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import '../runtime/global'
import { View, Group } from "./view" import { View, Group } from "./view"
import { loge } from '../util/log' import { loge } from '../util/log'
import { Model } from '../util/types' import { Model } from '../util/types'
@ -31,6 +30,8 @@ export function NativeCall(target: Panel, propertyKey: string, descriptor: Prope
type Frame = { width: number, height: number } type Frame = { width: number, height: number }
declare function nativeEmpty(): void
export abstract class Panel { export abstract class Panel {
context!: BridgeContext context!: BridgeContext
onCreate() { } onCreate() { }
@ -141,24 +142,43 @@ export abstract class Panel {
} }
private hookBeforeNativeCall() { private hookBeforeNativeCall() {
if (Environment.platform !== 'h5') {
this.__root__.clean()
for (let v of this.headviews.values()) {
v.clean()
}
}
} }
private hookAfterNativeCall() { private hookAfterNativeCall() {
//Here insert a native call to ensure the promise is resolved done. if (Environment.platform !== 'h5') {
Promise.resolve().then(() => { //Here insert a native call to ensure the promise is resolved done.
nativeEmpty()
if (this.__root__.isDirty()) { if (this.__root__.isDirty()) {
const model = this.__root__.toModel() const model = this.__root__.toModel()
this.nativeRender(model) this.nativeRender(model)
this.__root__.clean()
} }
for (let v of this.headviews.values()) { for (let v of this.headviews.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel() const model = v.toModel()
this.nativeRender(model) 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()
}
}
})
}
} }
} }