success to callback onClick function
This commit is contained in:
parent
7d08ceb8be
commit
341692f319
@ -1,5 +1,6 @@
|
|||||||
package com.github.penfeizhou.doric.shader;
|
package com.github.penfeizhou.doric.shader;
|
||||||
|
|
||||||
|
import android.util.TypedValue;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.github.penfeizhou.doric.DoricContext;
|
import com.github.penfeizhou.doric.DoricContext;
|
||||||
@ -29,6 +30,12 @@ public class TextNode extends ViewNode<TextView> {
|
|||||||
case "text":
|
case "text":
|
||||||
view.setText(prop.asString().toString());
|
view.setText(prop.asString().toString());
|
||||||
break;
|
break;
|
||||||
|
case "textSize":
|
||||||
|
view.setTextSize(TypedValue.COMPLEX_UNIT_DIP, prop.asNumber().toFloat());
|
||||||
|
break;
|
||||||
|
case "textColor":
|
||||||
|
view.setTextColor(prop.asNumber().toInt());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
super.blend(view, name, prop);
|
super.blend(view, name, prop);
|
||||||
break;
|
break;
|
||||||
|
@ -78,6 +78,15 @@ public abstract class ViewNode<T extends View> extends DoricComponent {
|
|||||||
case "bgColor":
|
case "bgColor":
|
||||||
view.setBackgroundColor(prop.asNumber().toInt());
|
view.setBackgroundColor(prop.asNumber().toInt());
|
||||||
break;
|
break;
|
||||||
|
case "onClick":
|
||||||
|
final String functionId = prop.asString().value();
|
||||||
|
view.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
callJSResponse(functionId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -100,7 +109,7 @@ public abstract class ViewNode<T extends View> extends DoricComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void callJSRespone(String funcId, Object... args) {
|
public void callJSResponse(String funcId, Object... args) {
|
||||||
final Object[] nArgs = new Object[args.length + 2];
|
final Object[] nArgs = new Object[args.length + 2];
|
||||||
nArgs[0] = ids.toArray(new String[0]);
|
nArgs[0] = ids.toArray(new String[0]);
|
||||||
nArgs[1] = funcId;
|
nArgs[1] = funcId;
|
||||||
|
@ -14,6 +14,7 @@ import com.github.pengfeizhou.jscore.JSONBuilder;
|
|||||||
import com.github.pengfeizhou.jscore.JSValue;
|
import com.github.pengfeizhou.jscore.JSValue;
|
||||||
import com.github.pengfeizhou.jscore.JavaValue;
|
import com.github.pengfeizhou.jscore.JavaValue;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -69,6 +70,12 @@ public class DoricUtils {
|
|||||||
return new JavaValue((Boolean) arg);
|
return new JavaValue((Boolean) arg);
|
||||||
} else if (arg instanceof JavaValue) {
|
} else if (arg instanceof JavaValue) {
|
||||||
return (JavaValue) arg;
|
return (JavaValue) arg;
|
||||||
|
} else if (arg instanceof Object[]) {
|
||||||
|
JSONArray jsonArray = new JSONArray();
|
||||||
|
for (Object o : (Object[]) arg) {
|
||||||
|
jsonArray.put(o);
|
||||||
|
}
|
||||||
|
return new JavaValue(jsonArray);
|
||||||
} else {
|
} else {
|
||||||
return new JavaValue(String.valueOf(arg));
|
return new JavaValue(String.valueOf(arg));
|
||||||
}
|
}
|
||||||
|
@ -5,16 +5,31 @@ import { Group } from "./src/ui/view";
|
|||||||
|
|
||||||
@Entry
|
@Entry
|
||||||
export class MyPage extends Panel {
|
export class MyPage extends Panel {
|
||||||
text?: Text
|
state = {
|
||||||
|
count: 0
|
||||||
|
}
|
||||||
|
|
||||||
build(rootView: Group): void {
|
build(rootView: Group): void {
|
||||||
this.text = new Text
|
const numberView = new Text
|
||||||
this.text.text = "hello"
|
numberView.width = 100
|
||||||
this.text.width = 50
|
numberView.height = 200
|
||||||
this.text.height = 50
|
numberView.top = 50
|
||||||
this.text.y = 100
|
numberView.text = this.state.count.toString()
|
||||||
rootView.children.push(this.text)
|
numberView.textSize = 40
|
||||||
|
numberView.centerX = rootView.width / 2
|
||||||
|
rootView.addChild(numberView)
|
||||||
|
const click = new Text
|
||||||
|
click.width = click.height = 100
|
||||||
|
click.textSize = 20
|
||||||
|
click.text = '点击计数'
|
||||||
|
click.onClick = () => {
|
||||||
|
this.state.count++
|
||||||
|
numberView.text = this.state.count.toString()
|
||||||
|
}
|
||||||
|
click.centerX = rootView.width / 2
|
||||||
|
click.top = numberView.bottom + 20
|
||||||
|
rootView.addChild(click)
|
||||||
rootView.bgColor = Color.safeParse('#00ff00')
|
rootView.bgColor = Color.safeParse('#00ff00')
|
||||||
log('build view:', JSON.stringify(rootView.toModel()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NativeCall
|
@NativeCall
|
||||||
@ -22,29 +37,5 @@ export class MyPage extends Panel {
|
|||||||
log("Hello.HEGO")
|
log("Hello.HEGO")
|
||||||
logw("Hello.HEGO")
|
logw("Hello.HEGO")
|
||||||
loge("Hello.HEGO")
|
loge("Hello.HEGO")
|
||||||
|
|
||||||
context.demo.testPromise(true).then((r) => {
|
|
||||||
log('resolve', r)
|
|
||||||
}, (e) => {
|
|
||||||
log('reject', e)
|
|
||||||
})
|
|
||||||
|
|
||||||
context.demo.testPromise(false).then((r) => {
|
|
||||||
log('resolve', r)
|
|
||||||
}, (e) => {
|
|
||||||
log('reject', e)
|
|
||||||
})
|
|
||||||
|
|
||||||
setTimeout(function () {
|
|
||||||
log('settimeout')
|
|
||||||
}, 1000)
|
|
||||||
|
|
||||||
setInterval(() => {
|
|
||||||
log('setInterval')
|
|
||||||
if (this.text) {
|
|
||||||
this.text.y += 10
|
|
||||||
}
|
|
||||||
log('build view:', JSON.stringify(this.getRootView().toModel()))
|
|
||||||
}, 1000)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -36,7 +36,6 @@ export abstract class Panel {
|
|||||||
|
|
||||||
@NativeCall
|
@NativeCall
|
||||||
private __init__(frame: Frame, data: any) {
|
private __init__(frame: Frame, data: any) {
|
||||||
log('__init__:', frame, data)
|
|
||||||
this.__data__ = data
|
this.__data__ = data
|
||||||
this.__root__.width = frame.width
|
this.__root__.width = frame.width
|
||||||
this.__root__.height = frame.height
|
this.__root__.height = frame.height
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -58,12 +58,12 @@ export abstract class View implements Modeling {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
return new Proxy(this, {
|
return new Proxy(this, {
|
||||||
get: (target, p) => {
|
get: (target, p, receiver) => {
|
||||||
return Reflect.get(target, p)
|
return Reflect.get(target, p, receiver)
|
||||||
},
|
},
|
||||||
set: (target, p, v, receiver) => {
|
set: (target, p, v, receiver) => {
|
||||||
const oldV = Reflect.get(target, p)
|
const oldV = Reflect.get(target, p, receiver)
|
||||||
const ret = Reflect.set(target, p, v)
|
const ret = Reflect.set(target, p, v, receiver)
|
||||||
if (Reflect.getMetadata(p, target)) {
|
if (Reflect.getMetadata(p, target)) {
|
||||||
receiver.onPropertyChanged(p.toString(), oldV, v)
|
receiver.onPropertyChanged(p.toString(), oldV, v)
|
||||||
}
|
}
|
||||||
@ -101,6 +101,22 @@ export abstract class View implements Modeling {
|
|||||||
set bottom(v: number) {
|
set bottom(v: number) {
|
||||||
this.y = v - this.height
|
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*/
|
/** Anchor end*/
|
||||||
|
|
||||||
__dirty_props__: { [index: string]: Model | undefined } = {}
|
__dirty_props__: { [index: string]: Model | undefined } = {}
|
||||||
@ -212,6 +228,9 @@ export abstract class Group extends View {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
addChild(view: View) {
|
||||||
|
this.children.push(view)
|
||||||
|
}
|
||||||
clean() {
|
clean() {
|
||||||
this.children.forEach(e => { e.clean() })
|
this.children.forEach(e => { e.clean() })
|
||||||
super.clean()
|
super.clean()
|
||||||
@ -232,7 +251,6 @@ export abstract class Group extends View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onChildPropertyChanged(child: View, propKey: string, oldV: Model, newV: Model) {
|
onChildPropertyChanged(child: View, propKey: string, oldV: Model, newV: Model) {
|
||||||
loge('onChildPropertyChanged:' + (this.children.indexOf(child)))
|
|
||||||
this.getDirtyChildrenModel()[this.children.indexOf(child)] = child.nativeViewModel
|
this.getDirtyChildrenModel()[this.children.indexOf(child)] = child.nativeViewModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -270,6 +288,9 @@ export class Text extends View {
|
|||||||
|
|
||||||
@Property
|
@Property
|
||||||
maxLines?: number
|
maxLines?: number
|
||||||
|
|
||||||
|
@Property
|
||||||
|
onClick?: Function
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Image extends View {
|
export class Image extends View {
|
||||||
|
Reference in New Issue
Block a user