feat: add ModularPanel

This commit is contained in:
pengfei.zhou
2021-05-13 14:50:54 +08:00
committed by osborn
parent edcfb66c5d
commit 300343909a
15 changed files with 179 additions and 54 deletions

14
doric-js/lib/src/pattern/modular.d.ts vendored Normal file
View File

@@ -0,0 +1,14 @@
import { Panel } from "../ui/panel";
import { Group } from "../ui/view";
export declare abstract class ModularPanel extends Panel {
private modules;
constructor(modules: Panel[]);
abstract setupModules(): Panel[];
abstract setupShelf(root: Group): Group;
build(root: Group): void;
onCreate(): void;
onDestroy(): void;
onShow(): void;
onHidden(): void;
onRenderFinished(): void;
}

View File

@@ -0,0 +1,45 @@
import { Panel } from "../ui/panel";
export class ModularPanel extends Panel {
constructor(modules) {
super();
this.modules = [];
this.modules = modules;
}
build(root) {
const groupView = this.setupShelf(root);
this.modules.forEach(e => {
Reflect.set(e, "__root__", groupView);
e.build(groupView);
});
}
onCreate() {
super.onCreate();
this.modules.forEach(e => {
e.onCreate();
});
}
onDestroy() {
super.onDestroy();
this.modules.forEach(e => {
e.onDestroy();
});
}
onShow() {
super.onShow();
this.modules.forEach(e => {
e.onShow();
});
}
onHidden() {
super.onHidden();
this.modules.forEach(e => {
e.onHidden();
});
}
onRenderFinished() {
super.onRenderFinished();
this.modules.forEach(e => {
e.onRenderFinished();
});
}
}

View File

@@ -1,6 +1,7 @@
import { Group } from "../ui/view";
import { Panel } from "../ui/panel";
import { BridgeContext } from "../runtime/global";
import { ClassType } from "../util/types";
export declare abstract class ViewHolder {
abstract build(root: Group): void;
}
@@ -17,7 +18,6 @@ export declare abstract class ViewModel<M extends Object, V extends ViewHolder>
abstract onAttached(state: M, vh: V): void;
abstract onBind(state: M, vh: V): void;
}
export declare type ClassType<T> = new (...args: any) => T;
export declare abstract class VMPanel<M extends Object, V extends ViewHolder> extends Panel {
private vm?;
private vh?;