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

View File

@@ -1,6 +1,6 @@
import { BridgeContext } from "../runtime/global";
import { ClassType } from "../pattern/mvvm";
import { Panel } from "../ui/panel";
import { ClassType } from "../util/types";
export declare function internalScheme(context: BridgeContext, panelClass: ClassType<Panel>): string;
export declare function navigator(context: BridgeContext): {
push: (source: string | ClassType<Panel>, config?: {

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?;

View File

@@ -1,5 +1,5 @@
import { Panel } from "../ui/panel";
import { ClassType } from "../pattern/mvvm";
import { ClassType } from "../util/types";
export declare type BridgeContext = {
/**
* The identify of current context

View File

@@ -32,6 +32,6 @@ export declare abstract class Panel {
private nativeRender;
private hookBeforeNativeCall;
private hookAfterNativeCall;
private onRenderFinished;
onRenderFinished(): void;
addOnRenderFinishedCallback(cb: () => void): void;
}

View File

@@ -16,4 +16,5 @@ export declare class Mutable<T> {
bind(binder: Binder<T>): void;
static of<E>(v: E): Mutable<E>;
}
export declare type ClassType<T> = new (...args: any) => T;
export {};