head view manipulation api changed

This commit is contained in:
王劲鹏 2020-01-09 11:17:44 +08:00 committed by osborn
parent 88d45c2967
commit 56852286e3
10 changed files with 219 additions and 128 deletions

View File

@ -671,22 +671,37 @@ class Panel {
onDestroy() { } onDestroy() { }
onShow() { } onShow() { }
onHidden() { } onHidden() { }
addHeadView(v) { addHeadView(type, v) {
this.headviews.set(v.viewId, v); let map = this.headviews.get(type);
if (map) {
map.set(v.viewId, v);
}
else {
map = new Map;
map.set(v.viewId, v);
this.headviews.set(type, map);
}
} }
allHeadViews() { allHeadViews() {
return this.headviews.values(); return this.headviews.values();
} }
removeHeadView(v) { removeHeadView(type, v) {
if (this.headviews.has(type)) {
let map = this.headviews.get(type);
if (map) {
if (v instanceof View) { if (v instanceof View) {
this.headviews.delete(v.viewId); map.delete(v.viewId);
} }
else { else {
this.headviews.delete(v); map.delete(v);
} }
} }
clearHeadViews() { }
this.headviews.clear(); }
clearHeadViews(type) {
if (this.headviews.has(type)) {
this.headviews.delete(type);
}
} }
getRootView() { getRootView() {
return this.__root__; return this.__root__;
@ -753,11 +768,13 @@ class Panel {
hookBeforeNativeCall() { hookBeforeNativeCall() {
if (Environment.platform !== 'h5') { if (Environment.platform !== 'h5') {
this.__root__.clean(); this.__root__.clean();
for (let v of this.headviews.values()) { for (let map of this.headviews.values()) {
for (let v of map.values()) {
v.clean(); v.clean();
} }
} }
} }
}
hookAfterNativeCall() { hookAfterNativeCall() {
if (Environment.platform !== 'h5') { if (Environment.platform !== 'h5') {
//Here insert a native call to ensure the promise is resolved done. //Here insert a native call to ensure the promise is resolved done.
@ -766,13 +783,15 @@ class Panel {
const model = this.__root__.toModel(); const model = this.__root__.toModel();
this.nativeRender(model); this.nativeRender(model);
} }
for (let v of this.headviews.values()) { for (let map of this.headviews.values()) {
for (let v of map.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel(); const model = v.toModel();
this.nativeRender(model); this.nativeRender(model);
} }
} }
} }
}
else { else {
Promise.resolve().then(() => { Promise.resolve().then(() => {
if (this.__root__.isDirty()) { if (this.__root__.isDirty()) {
@ -780,13 +799,15 @@ class Panel {
this.nativeRender(model); this.nativeRender(model);
this.__root__.clean(); this.__root__.clean();
} }
for (let v of this.headviews.values()) { for (let map of this.headviews.values()) {
for (let v of map.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel(); const model = v.toModel();
this.nativeRender(model); this.nativeRender(model);
v.clean(); v.clean();
} }
} }
}
}); });
} }
} }
@ -1944,17 +1965,17 @@ function popover(context) {
return { return {
show: (view) => { show: (view) => {
if (panel) { if (panel) {
panel.addHeadView(view); panel.addHeadView("popover", view);
} }
return context.popover.show(view.toModel()); return context.popover.show(view.toModel());
}, },
dismiss: (view = undefined) => { dismiss: (view = undefined) => {
if (panel) { if (panel) {
if (view) { if (view) {
panel.removeHeadView(view); panel.removeHeadView("popover", view);
} }
else { else {
panel.clearHeadViews(); panel.clearHeadViews("popover");
} }
} }
return context.popover.dismiss(view ? { id: view.viewId } : undefined); return context.popover.dismiss(view ? { id: view.viewId } : undefined);
@ -2060,7 +2081,8 @@ function animate(context) {
root.clean(); root.clean();
return ret; return ret;
} }
for (let v of panel.allHeadViews()) { for (let map of panel.allHeadViews()) {
for (let v of map.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel(); const model = v.toModel();
const ret = it.animateRender(model); const ret = it.animateRender(model);
@ -2068,6 +2090,7 @@ function animate(context) {
return ret; return ret;
} }
} }
}
throw new Error('Cannot find any animated elements'); throw new Error('Cannot find any animated elements');
}); });
}); });

View File

@ -2130,22 +2130,37 @@ class Panel {
onDestroy() { } onDestroy() { }
onShow() { } onShow() { }
onHidden() { } onHidden() { }
addHeadView(v) { addHeadView(type, v) {
this.headviews.set(v.viewId, v); let map = this.headviews.get(type);
if (map) {
map.set(v.viewId, v);
}
else {
map = new Map;
map.set(v.viewId, v);
this.headviews.set(type, map);
}
} }
allHeadViews() { allHeadViews() {
return this.headviews.values(); return this.headviews.values();
} }
removeHeadView(v) { removeHeadView(type, v) {
if (this.headviews.has(type)) {
let map = this.headviews.get(type);
if (map) {
if (v instanceof View) { if (v instanceof View) {
this.headviews.delete(v.viewId); map.delete(v.viewId);
} }
else { else {
this.headviews.delete(v); map.delete(v);
} }
} }
clearHeadViews() { }
this.headviews.clear(); }
clearHeadViews(type) {
if (this.headviews.has(type)) {
this.headviews.delete(type);
}
} }
getRootView() { getRootView() {
return this.__root__; return this.__root__;
@ -2212,11 +2227,13 @@ class Panel {
hookBeforeNativeCall() { hookBeforeNativeCall() {
if (Environment.platform !== 'h5') { if (Environment.platform !== 'h5') {
this.__root__.clean(); this.__root__.clean();
for (let v of this.headviews.values()) { for (let map of this.headviews.values()) {
for (let v of map.values()) {
v.clean(); v.clean();
} }
} }
} }
}
hookAfterNativeCall() { hookAfterNativeCall() {
if (Environment.platform !== 'h5') { if (Environment.platform !== 'h5') {
//Here insert a native call to ensure the promise is resolved done. //Here insert a native call to ensure the promise is resolved done.
@ -2225,13 +2242,15 @@ class Panel {
const model = this.__root__.toModel(); const model = this.__root__.toModel();
this.nativeRender(model); this.nativeRender(model);
} }
for (let v of this.headviews.values()) { for (let map of this.headviews.values()) {
for (let v of map.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel(); const model = v.toModel();
this.nativeRender(model); this.nativeRender(model);
} }
} }
} }
}
else { else {
Promise.resolve().then(() => { Promise.resolve().then(() => {
if (this.__root__.isDirty()) { if (this.__root__.isDirty()) {
@ -2239,13 +2258,15 @@ class Panel {
this.nativeRender(model); this.nativeRender(model);
this.__root__.clean(); this.__root__.clean();
} }
for (let v of this.headviews.values()) { for (let map of this.headviews.values()) {
for (let v of map.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel(); const model = v.toModel();
this.nativeRender(model); this.nativeRender(model);
v.clean(); v.clean();
} }
} }
}
}); });
} }
} }
@ -3403,17 +3424,17 @@ function popover(context) {
return { return {
show: (view) => { show: (view) => {
if (panel) { if (panel) {
panel.addHeadView(view); panel.addHeadView("popover", view);
} }
return context.popover.show(view.toModel()); return context.popover.show(view.toModel());
}, },
dismiss: (view = undefined) => { dismiss: (view = undefined) => {
if (panel) { if (panel) {
if (view) { if (view) {
panel.removeHeadView(view); panel.removeHeadView("popover", view);
} }
else { else {
panel.clearHeadViews(); panel.clearHeadViews("popover");
} }
} }
return context.popover.dismiss(view ? { id: view.viewId } : undefined); return context.popover.dismiss(view ? { id: view.viewId } : undefined);
@ -3519,7 +3540,8 @@ function animate(context) {
root.clean(); root.clean();
return ret; return ret;
} }
for (let v of panel.allHeadViews()) { for (let map of panel.allHeadViews()) {
for (let v of map.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel(); const model = v.toModel();
const ret = it.animateRender(model); const ret = it.animateRender(model);
@ -3527,6 +3549,7 @@ function animate(context) {
return ret; return ret;
} }
} }
}
throw new Error('Cannot find any animated elements'); throw new Error('Cannot find any animated elements');
}); });
}); });

8
doric-js/index.d.ts vendored
View File

@ -256,10 +256,10 @@ declare module 'doric/lib/src/ui/panel' {
onShow(): void; onShow(): void;
onHidden(): void; onHidden(): void;
abstract build(rootView: Group): void; abstract build(rootView: Group): void;
addHeadView(v: View): void; addHeadView(type: string, v: View): void;
allHeadViews(): IterableIterator<View>; allHeadViews(): IterableIterator<Map<string, View>>;
removeHeadView(v: View | string): void; removeHeadView(type: string, v: View | string): void;
clearHeadViews(): void; clearHeadViews(type: string): void;
getRootView(): Root; getRootView(): Root;
getInitData(): object | undefined; getInitData(): object | undefined;
} }

View File

@ -35,7 +35,8 @@ export function animate(context) {
root.clean(); root.clean();
return ret; return ret;
} }
for (let v of panel.allHeadViews()) { for (let map of panel.allHeadViews()) {
for (let v of map.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel(); const model = v.toModel();
const ret = it.animateRender(model); const ret = it.animateRender(model);
@ -43,6 +44,7 @@ export function animate(context) {
return ret; return ret;
} }
} }
}
throw new Error('Cannot find any animated elements'); throw new Error('Cannot find any animated elements');
}); });
}); });

View File

@ -8,17 +8,17 @@ export function popover(context) {
return { return {
show: (view) => { show: (view) => {
if (panel) { if (panel) {
panel.addHeadView(view); panel.addHeadView("popover", view);
} }
return context.popover.show(view.toModel()); return context.popover.show(view.toModel());
}, },
dismiss: (view = undefined) => { dismiss: (view = undefined) => {
if (panel) { if (panel) {
if (view) { if (view) {
panel.removeHeadView(view); panel.removeHeadView("popover", view);
} }
else { else {
panel.clearHeadViews(); panel.clearHeadViews("popover");
} }
} }
return context.popover.dismiss(view ? { id: view.viewId } : undefined); return context.popover.dismiss(view ? { id: view.viewId } : undefined);

View File

@ -12,10 +12,10 @@ export declare abstract class Panel {
private __data__?; private __data__?;
private __root__; private __root__;
private headviews; private headviews;
addHeadView(v: View): void; addHeadView(type: string, v: View): void;
allHeadViews(): IterableIterator<View>; allHeadViews(): IterableIterator<Map<string, View>>;
removeHeadView(v: View | string): void; removeHeadView(type: string, v: View | string): void;
clearHeadViews(): void; clearHeadViews(type: string): void;
getRootView(): Root; getRootView(): Root;
getInitData(): object | undefined; getInitData(): object | undefined;
private __init__; private __init__;

View File

@ -42,22 +42,37 @@ export class Panel {
onDestroy() { } onDestroy() { }
onShow() { } onShow() { }
onHidden() { } onHidden() { }
addHeadView(v) { addHeadView(type, v) {
this.headviews.set(v.viewId, v); let map = this.headviews.get(type);
if (map) {
map.set(v.viewId, v);
}
else {
map = new Map;
map.set(v.viewId, v);
this.headviews.set(type, map);
}
} }
allHeadViews() { allHeadViews() {
return this.headviews.values(); return this.headviews.values();
} }
removeHeadView(v) { removeHeadView(type, v) {
if (this.headviews.has(type)) {
let map = this.headviews.get(type);
if (map) {
if (v instanceof View) { if (v instanceof View) {
this.headviews.delete(v.viewId); map.delete(v.viewId);
} }
else { else {
this.headviews.delete(v); map.delete(v);
} }
} }
clearHeadViews() { }
this.headviews.clear(); }
clearHeadViews(type) {
if (this.headviews.has(type)) {
this.headviews.delete(type);
}
} }
getRootView() { getRootView() {
return this.__root__; return this.__root__;
@ -124,11 +139,13 @@ export class Panel {
hookBeforeNativeCall() { hookBeforeNativeCall() {
if (Environment.platform !== 'h5') { if (Environment.platform !== 'h5') {
this.__root__.clean(); this.__root__.clean();
for (let v of this.headviews.values()) { for (let map of this.headviews.values()) {
for (let v of map.values()) {
v.clean(); v.clean();
} }
} }
} }
}
hookAfterNativeCall() { hookAfterNativeCall() {
if (Environment.platform !== 'h5') { if (Environment.platform !== 'h5') {
//Here insert a native call to ensure the promise is resolved done. //Here insert a native call to ensure the promise is resolved done.
@ -137,13 +154,15 @@ export class Panel {
const model = this.__root__.toModel(); const model = this.__root__.toModel();
this.nativeRender(model); this.nativeRender(model);
} }
for (let v of this.headviews.values()) { for (let map of this.headviews.values()) {
for (let v of map.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel(); const model = v.toModel();
this.nativeRender(model); this.nativeRender(model);
} }
} }
} }
}
else { else {
Promise.resolve().then(() => { Promise.resolve().then(() => {
if (this.__root__.isDirty()) { if (this.__root__.isDirty()) {
@ -151,13 +170,15 @@ export class Panel {
this.nativeRender(model); this.nativeRender(model);
this.__root__.clean(); this.__root__.clean();
} }
for (let v of this.headviews.values()) { for (let map of this.headviews.values()) {
for (let v of map.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel(); const model = v.toModel();
this.nativeRender(model); this.nativeRender(model);
v.clean(); v.clean();
} }
} }
}
}); });
} }
} }

View File

@ -39,7 +39,8 @@ export function animate(context: BridgeContext) {
root.clean() root.clean()
return ret return ret
} }
for (let v of panel.allHeadViews()) { for (let map of panel.allHeadViews()) {
for (let v of map.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel() const model = v.toModel()
const ret = it.animateRender(model) const ret = it.animateRender(model)
@ -47,6 +48,7 @@ export function animate(context: BridgeContext) {
return ret return ret
} }
} }
}
throw new Error('Cannot find any animated elements') throw new Error('Cannot find any animated elements')
}) })
}) })

View File

@ -26,16 +26,16 @@ export function popover(context: BridgeContext) {
return { return {
show: (view: View) => { show: (view: View) => {
if (panel) { if (panel) {
panel.addHeadView(view) panel.addHeadView("popover", view)
} }
return context.popover.show(view.toModel()) return context.popover.show(view.toModel())
}, },
dismiss: (view: View | undefined = undefined) => { dismiss: (view: View | undefined = undefined) => {
if (panel) { if (panel) {
if (view) { if (view) {
panel.removeHeadView(view) panel.removeHeadView("popover", view)
} else { } else {
panel.clearHeadViews() panel.clearHeadViews("popover")
} }
} }
return context.popover.dismiss(view ? { id: view.viewId } : undefined) return context.popover.dismiss(view ? { id: view.viewId } : undefined)

View File

@ -43,24 +43,38 @@ export abstract class Panel {
private __data__?: object private __data__?: object
private __root__ = new Root private __root__ = new Root
private headviews: Map<string, View> = new Map private headviews: Map<string, Map<string, View>> = new Map
addHeadView(v: View) { addHeadView(type: string, v: View) {
this.headviews.set(v.viewId, v) let map = this.headviews.get(type)
if (map) {
map.set(v.viewId, v)
} else {
map = new Map
map.set(v.viewId, v)
this.headviews.set(type, map)
}
} }
allHeadViews() { allHeadViews() {
return this.headviews.values() return this.headviews.values()
} }
removeHeadView(v: View | string) { removeHeadView(type: string, v: View | string) {
if (this.headviews.has(type)) {
let map = this.headviews.get(type)
if (map) {
if (v instanceof View) { if (v instanceof View) {
this.headviews.delete(v.viewId) map.delete(v.viewId)
} else { } else {
this.headviews.delete(v) map.delete(v)
}
}
} }
} }
clearHeadViews() { clearHeadViews(type: string) {
this.headviews.clear() if (this.headviews.has(type)) {
this.headviews.delete(type)
}
} }
getRootView() { getRootView() {
@ -144,11 +158,13 @@ export abstract class Panel {
private hookBeforeNativeCall() { private hookBeforeNativeCall() {
if (Environment.platform !== 'h5') { if (Environment.platform !== 'h5') {
this.__root__.clean() this.__root__.clean()
for (let v of this.headviews.values()) { for (let map of this.headviews.values()) {
for (let v of map.values()) {
v.clean() v.clean()
} }
} }
} }
}
private hookAfterNativeCall() { private hookAfterNativeCall() {
if (Environment.platform !== 'h5') { if (Environment.platform !== 'h5') {
@ -158,12 +174,14 @@ export abstract class Panel {
const model = this.__root__.toModel() const model = this.__root__.toModel()
this.nativeRender(model) this.nativeRender(model)
} }
for (let v of this.headviews.values()) { for (let map of this.headviews.values()) {
for (let v of map.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel() const model = v.toModel()
this.nativeRender(model) this.nativeRender(model)
} }
} }
}
} else { } else {
Promise.resolve().then(() => { Promise.resolve().then(() => {
if (this.__root__.isDirty()) { if (this.__root__.isDirty()) {
@ -171,13 +189,15 @@ export abstract class Panel {
this.nativeRender(model) this.nativeRender(model)
this.__root__.clean() this.__root__.clean()
} }
for (let v of this.headviews.values()) { for (let map of this.headviews.values()) {
for (let v of map.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel() const model = v.toModel()
this.nativeRender(model) this.nativeRender(model)
v.clean() v.clean()
} }
} }
}
}) })
} }
} }