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 (v instanceof View) { if (this.headviews.has(type)) {
this.headviews.delete(v.viewId); let map = this.headviews.get(type);
} if (map) {
else { if (v instanceof View) {
this.headviews.delete(v); map.delete(v.viewId);
}
else {
map.delete(v);
}
}
} }
} }
clearHeadViews() { clearHeadViews(type) {
this.headviews.clear(); if (this.headviews.has(type)) {
this.headviews.delete(type);
}
} }
getRootView() { getRootView() {
return this.__root__; return this.__root__;
@ -753,8 +768,10 @@ 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()) {
v.clean(); for (let v of map.values()) {
v.clean();
}
} }
} }
} }
@ -766,10 +783,12 @@ 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()) {
if (v.isDirty()) { for (let v of map.values()) {
const model = v.toModel(); if (v.isDirty()) {
this.nativeRender(model); const model = v.toModel();
this.nativeRender(model);
}
} }
} }
} }
@ -780,11 +799,13 @@ 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()) {
if (v.isDirty()) { for (let v of map.values()) {
const model = v.toModel(); if (v.isDirty()) {
this.nativeRender(model); const model = v.toModel();
v.clean(); this.nativeRender(model);
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,12 +2081,14 @@ function animate(context) {
root.clean(); root.clean();
return ret; return ret;
} }
for (let v of panel.allHeadViews()) { for (let map of panel.allHeadViews()) {
if (v.isDirty()) { for (let v of map.values()) {
const model = v.toModel(); if (v.isDirty()) {
const ret = it.animateRender(model); const model = v.toModel();
it.clean(); const ret = it.animateRender(model);
return ret; it.clean();
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 (v instanceof View) { if (this.headviews.has(type)) {
this.headviews.delete(v.viewId); let map = this.headviews.get(type);
} if (map) {
else { if (v instanceof View) {
this.headviews.delete(v); map.delete(v.viewId);
}
else {
map.delete(v);
}
}
} }
} }
clearHeadViews() { clearHeadViews(type) {
this.headviews.clear(); if (this.headviews.has(type)) {
this.headviews.delete(type);
}
} }
getRootView() { getRootView() {
return this.__root__; return this.__root__;
@ -2212,8 +2227,10 @@ 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()) {
v.clean(); for (let v of map.values()) {
v.clean();
}
} }
} }
} }
@ -2225,10 +2242,12 @@ 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()) {
if (v.isDirty()) { for (let v of map.values()) {
const model = v.toModel(); if (v.isDirty()) {
this.nativeRender(model); const model = v.toModel();
this.nativeRender(model);
}
} }
} }
} }
@ -2239,11 +2258,13 @@ 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()) {
if (v.isDirty()) { for (let v of map.values()) {
const model = v.toModel(); if (v.isDirty()) {
this.nativeRender(model); const model = v.toModel();
v.clean(); this.nativeRender(model);
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,12 +3540,14 @@ function animate(context) {
root.clean(); root.clean();
return ret; return ret;
} }
for (let v of panel.allHeadViews()) { for (let map of panel.allHeadViews()) {
if (v.isDirty()) { for (let v of map.values()) {
const model = v.toModel(); if (v.isDirty()) {
const ret = it.animateRender(model); const model = v.toModel();
it.clean(); const ret = it.animateRender(model);
return ret; it.clean();
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,12 +35,14 @@ export function animate(context) {
root.clean(); root.clean();
return ret; return ret;
} }
for (let v of panel.allHeadViews()) { for (let map of panel.allHeadViews()) {
if (v.isDirty()) { for (let v of map.values()) {
const model = v.toModel(); if (v.isDirty()) {
const ret = it.animateRender(model); const model = v.toModel();
it.clean(); const ret = it.animateRender(model);
return ret; it.clean();
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 (v instanceof View) { if (this.headviews.has(type)) {
this.headviews.delete(v.viewId); let map = this.headviews.get(type);
} if (map) {
else { if (v instanceof View) {
this.headviews.delete(v); map.delete(v.viewId);
}
else {
map.delete(v);
}
}
} }
} }
clearHeadViews() { clearHeadViews(type) {
this.headviews.clear(); if (this.headviews.has(type)) {
this.headviews.delete(type);
}
} }
getRootView() { getRootView() {
return this.__root__; return this.__root__;
@ -124,8 +139,10 @@ 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()) {
v.clean(); for (let v of map.values()) {
v.clean();
}
} }
} }
} }
@ -137,10 +154,12 @@ 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()) {
if (v.isDirty()) { for (let v of map.values()) {
const model = v.toModel(); if (v.isDirty()) {
this.nativeRender(model); const model = v.toModel();
this.nativeRender(model);
}
} }
} }
} }
@ -151,11 +170,13 @@ 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()) {
if (v.isDirty()) { for (let v of map.values()) {
const model = v.toModel(); if (v.isDirty()) {
this.nativeRender(model); const model = v.toModel();
v.clean(); this.nativeRender(model);
v.clean();
}
} }
} }
}); });

View File

@ -39,12 +39,14 @@ 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()) {
if (v.isDirty()) { for (let v of map.values()) {
const model = v.toModel() if (v.isDirty()) {
const ret = it.animateRender(model) const model = v.toModel()
it.clean() const ret = it.animateRender(model)
return ret it.clean()
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 (v instanceof View) { if (this.headviews.has(type)) {
this.headviews.delete(v.viewId) let map = this.headviews.get(type)
} else { if (map) {
this.headviews.delete(v) if (v instanceof View) {
map.delete(v.viewId)
} else {
map.delete(v)
}
}
} }
} }
clearHeadViews() { clearHeadViews(type: string) {
this.headviews.clear() if (this.headviews.has(type)) {
this.headviews.delete(type)
}
} }
getRootView() { getRootView() {
@ -144,8 +158,10 @@ 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()) {
v.clean() for (let v of map.values()) {
v.clean()
}
} }
} }
} }
@ -158,10 +174,12 @@ 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()) {
if (v.isDirty()) { for (let v of map.values()) {
const model = v.toModel() if (v.isDirty()) {
this.nativeRender(model) const model = v.toModel()
this.nativeRender(model)
}
} }
} }
} else { } else {
@ -171,11 +189,13 @@ 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()) {
if (v.isDirty()) { for (let v of map.values()) {
const model = v.toModel() if (v.isDirty()) {
this.nativeRender(model) const model = v.toModel()
v.clean() this.nativeRender(model)
v.clean()
}
} }
} }
}) })