tsx:add ref and parent support
This commit is contained in:
@@ -65,6 +65,25 @@ export type NativeViewModel = {
|
||||
};
|
||||
}
|
||||
|
||||
export class Ref<T extends View> {
|
||||
private view?: T;
|
||||
|
||||
set current(v: T) {
|
||||
this.view = v
|
||||
}
|
||||
|
||||
get current() {
|
||||
if (!!!this.view) {
|
||||
throw new Error("Ref is empty")
|
||||
}
|
||||
return this.view
|
||||
}
|
||||
}
|
||||
|
||||
export function makeRef() {
|
||||
return new Ref
|
||||
}
|
||||
|
||||
export abstract class View implements Modeling {
|
||||
private __dirty_props__!: { [index: string]: Model | undefined }
|
||||
|
||||
@@ -345,6 +364,18 @@ export abstract class View implements Modeling {
|
||||
@Property
|
||||
flexConfig?: FlexConfig
|
||||
|
||||
set props(props: Partial<this>) {
|
||||
this.apply(props)
|
||||
}
|
||||
|
||||
set parent(v: Group) {
|
||||
this.in(v)
|
||||
}
|
||||
|
||||
set ref(ref: Ref<this>) {
|
||||
ref.current = this
|
||||
}
|
||||
|
||||
doAnimation(context: BridgeContext, animation: IAnimation) {
|
||||
return this.nativeChannel(context, "doAnimation")(animation.toModel()).then((args) => {
|
||||
for (let key in args) {
|
||||
|
@@ -47,6 +47,25 @@ export type NativeViewModel = {
|
||||
};
|
||||
}
|
||||
|
||||
export class Ref<T extends View> {
|
||||
private view?: T;
|
||||
|
||||
set current(v: T) {
|
||||
this.view = v
|
||||
}
|
||||
|
||||
get current() {
|
||||
if (!!!this.view) {
|
||||
throw new Error("Ref is empty")
|
||||
}
|
||||
return this.view
|
||||
}
|
||||
}
|
||||
|
||||
export function makeRef<T extends View>(): Ref<T> {
|
||||
return new Ref
|
||||
}
|
||||
|
||||
export abstract class View implements Modeling {
|
||||
@Property
|
||||
width: number = 0
|
||||
@@ -358,6 +377,14 @@ export abstract class View implements Modeling {
|
||||
this.apply(props)
|
||||
}
|
||||
|
||||
set parent(v: Group) {
|
||||
this.in(v)
|
||||
}
|
||||
|
||||
set ref(ref: Ref<this>) {
|
||||
ref.current = this
|
||||
}
|
||||
|
||||
doAnimation(context: BridgeContext, animation: IAnimation) {
|
||||
return this.nativeChannel(context, "doAnimation")(animation.toModel()).then((args) => {
|
||||
for (let key in args) {
|
||||
|
Reference in New Issue
Block a user