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

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { Color, GradientColor } from "../util/color"
import { Modeling, Model, obj2Model } from "../util/types";
import { Modeling, Model, obj2Model, ClassType } from "../util/types";
import { uniqueId } from "../util/uniqueId";
import { loge } from "../util/log";
import { BridgeContext } from "../runtime/global";
@@ -50,6 +50,13 @@ export function InconsistProperty(target: Object, propKey: string) {
})
}
const PROP_KEY_VIEW_TYPE = "__prop__ViewType";
export function ViewComponent(constructor: ClassType<any>) {
const name = Reflect.get(constructor, PROP_KEY_VIEW_TYPE) || Object.getPrototypeOf(constructor).name
Reflect.set(constructor, PROP_KEY_VIEW_TYPE, name)
}
export type NativeViewModel = {
id: string;
type: string;
@@ -190,7 +197,7 @@ export abstract class View implements Modeling {
}
viewType() {
return this.constructor.name
return Reflect.get(this.constructor, PROP_KEY_VIEW_TYPE) || this.constructor.name
}
onPropertyChanged(propKey: string, oldV: Model, newV: Model): void {

View File

@@ -14,17 +14,17 @@
* limitations under the License.
*/
import { Color, GradientColor } from "../util/color"
import { Modeling, Model, obj2Model } from "../util/types";
import { Modeling, Model, obj2Model, ClassType } from "../util/types";
import { uniqueId } from "../util/uniqueId";
import { loge } from "../util/log";
import { BridgeContext } from "../runtime/global";
import { LayoutConfig } from '../util/layoutconfig'
import { IAnimation } from "./animation";
import { FlexConfig } from "../util/flexbox";
import { modal } from "../native/modal";
const PROP_CONSIST = 1;
const PROP_INCONSIST = 2;
const PROP_KEY_VIEW_TYPE = "ViewType";
export function Property(target: Object, propKey: string) {
Reflect.defineMetadata(propKey, PROP_CONSIST, target)
@@ -34,6 +34,11 @@ export function InconsistProperty(target: Object, propKey: string) {
Reflect.defineMetadata(propKey, PROP_INCONSIST, target)
}
export function ViewComponent(constructor: ClassType<any>) {
const name = Reflect.getMetadata(PROP_KEY_VIEW_TYPE, constructor) || Object.getPrototypeOf(constructor).name
Reflect.defineMetadata(PROP_KEY_VIEW_TYPE, name, constructor)
}
export type NativeViewModel = {
id: string;
type: string;
@@ -196,7 +201,8 @@ export abstract class View implements Modeling {
}
viewType() {
return this.constructor.name
const viewType = Reflect.getMetadata(PROP_KEY_VIEW_TYPE, this.constructor)
return viewType || this.constructor.name
}
onPropertyChanged(propKey: string, oldV: Model, newV: Model): void {