success to callback onClick function

This commit is contained in:
pengfei.zhou
2019-07-23 13:01:45 +08:00
parent 7d08ceb8be
commit 341692f319
7 changed files with 103 additions and 39 deletions

View File

@@ -36,7 +36,6 @@ export abstract class Panel {
@NativeCall
private __init__(frame: Frame, data: any) {
log('__init__:', frame, data)
this.__data__ = data
this.__root__.width = frame.width
this.__root__.height = frame.height

View File

@@ -0,0 +1,30 @@
function from(obj: Object) {
return new Proxy(obj, {
set: (target, prop, value, receiver) => {
return Reflect.set(target, prop, value, receiver)
}
})
}
class Wrapper {
val: any
constructor(val: any) {
this.val = val
}
toVal(): any {
return this.val
}
}
export class State {
static of<T extends Object>(obj: T): T {
return new Proxy(obj, {
get: (target, prop) => {
const ret = Reflect.get(target, prop)
if (ret instanceof Object) {
return State.of(ret)
} else {
return new Wrapper(ret)
}
}
})
}
}

View File

@@ -58,12 +58,12 @@ export abstract class View implements Modeling {
constructor() {
return new Proxy(this, {
get: (target, p) => {
return Reflect.get(target, p)
get: (target, p, receiver) => {
return Reflect.get(target, p, receiver)
},
set: (target, p, v, receiver) => {
const oldV = Reflect.get(target, p)
const ret = Reflect.set(target, p, v)
const oldV = Reflect.get(target, p, receiver)
const ret = Reflect.set(target, p, v, receiver)
if (Reflect.getMetadata(p, target)) {
receiver.onPropertyChanged(p.toString(), oldV, v)
}
@@ -101,6 +101,22 @@ export abstract class View implements Modeling {
set bottom(v: number) {
this.y = v - this.height
}
get centerX() {
return this.x + this.width / 2
}
get centerY() {
return this.y + this.height / 2
}
set centerX(v: number) {
this.x = v - this.width / 2
}
set centerY(v: number) {
this.y = v - this.height / 2
}
/** Anchor end*/
__dirty_props__: { [index: string]: Model | undefined } = {}
@@ -212,6 +228,9 @@ export abstract class Group extends View {
}
})
addChild(view: View) {
this.children.push(view)
}
clean() {
this.children.forEach(e => { e.clean() })
super.clean()
@@ -232,7 +251,6 @@ export abstract class Group extends View {
}
onChildPropertyChanged(child: View, propKey: string, oldV: Model, newV: Model) {
loge('onChildPropertyChanged:' + (this.children.indexOf(child)))
this.getDirtyChildrenModel()[this.children.indexOf(child)] = child.nativeViewModel
}
}
@@ -270,6 +288,9 @@ export class Text extends View {
@Property
maxLines?: number
@Property
onClick?: Function
}
export class Image extends View {