feat:support component view

This commit is contained in:
pengfei.zhou
2021-05-14 19:24:07 +08:00
committed by osborn
parent b6bfb210e1
commit 7ee30d1cd3
12 changed files with 215 additions and 15 deletions

View File

@@ -1,11 +1,12 @@
import { Color, GradientColor } from "../util/color";
import { Modeling, Model } from "../util/types";
import { Modeling, Model, ClassType } from "../util/types";
import { BridgeContext } from "../runtime/global";
import { LayoutConfig } from '../util/layoutconfig';
import { IAnimation } from "./animation";
import { FlexConfig } from "../util/flexbox";
export declare function Property(target: Object, propKey: string): void;
export declare function InconsistProperty(target: Object, propKey: string): void;
export declare function ViewComponent(constructor: ClassType<any>): void;
export declare type NativeViewModel = {
id: string;
type: string;
@@ -76,7 +77,7 @@ export declare abstract class View implements Modeling {
[index: string]: Model;
};
nativeViewModel: NativeViewModel;
viewType(): string;
viewType(): any;
onPropertyChanged(propKey: string, oldV: Model, newV: Model): void;
clean(): void;
isDirty(): boolean;

View File

@@ -12,12 +12,17 @@ import { uniqueId } from "../util/uniqueId";
import { loge } from "../util/log";
const PROP_CONSIST = 1;
const PROP_INCONSIST = 2;
const PROP_KEY_VIEW_TYPE = "ViewType";
export function Property(target, propKey) {
Reflect.defineMetadata(propKey, PROP_CONSIST, target);
}
export function InconsistProperty(target, propKey) {
Reflect.defineMetadata(propKey, PROP_INCONSIST, target);
}
export function ViewComponent(constructor) {
const name = Reflect.getMetadata(PROP_KEY_VIEW_TYPE, constructor) || Object.getPrototypeOf(constructor).name;
Reflect.defineMetadata(PROP_KEY_VIEW_TYPE, name, constructor);
}
export class View {
constructor() {
this.width = 0;
@@ -109,7 +114,8 @@ export class View {
return this.__dirty_props__;
}
viewType() {
return this.constructor.name;
const viewType = Reflect.getMetadata(PROP_KEY_VIEW_TYPE, this.constructor);
return viewType || this.constructor.name;
}
onPropertyChanged(propKey, oldV, newV) {
if (newV instanceof Function) {