diff --git a/Android/app/src/main/java/com/github/penfeizhou/doricdemo/MainActivity.java b/Android/app/src/main/java/com/github/penfeizhou/doricdemo/MainActivity.java index ce001567..2cf16a8b 100644 --- a/Android/app/src/main/java/com/github/penfeizhou/doricdemo/MainActivity.java +++ b/Android/app/src/main/java/com/github/penfeizhou/doricdemo/MainActivity.java @@ -5,6 +5,7 @@ import android.os.Bundle; import com.github.penfeizhou.doric.DoricContext; import com.github.penfeizhou.doric.utils.DoricUtils; +import com.github.pengfeizhou.jscore.JSONBuilder; public class MainActivity extends AppCompatActivity { @@ -13,6 +14,7 @@ public class MainActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); DoricContext doricContext = DoricContext.create(this, DoricUtils.readAssetFile("demo.js"), "demo"); + doricContext.callEntity("__init__", new JSONBuilder().put("width", 100).put("height", 100)); doricContext.callEntity("log"); } } diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/DoricRegistry.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/DoricRegistry.java index fcc85189..9d28589a 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/DoricRegistry.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/DoricRegistry.java @@ -2,6 +2,7 @@ package com.github.penfeizhou.doric; import android.text.TextUtils; +import com.github.penfeizhou.doric.plugin.ShaderPlugin; import com.github.penfeizhou.doric.widget.ViewNode; import com.github.penfeizhou.doric.utils.DoricMetaInfo; import com.github.penfeizhou.doric.plugin.DoricJavaPlugin; @@ -36,6 +37,7 @@ public class DoricRegistry { } public DoricRegistry() { + this.registerNativePlugin(ShaderPlugin.class); this.registerNativePlugin(ModalPlugin.class); initRegistry(this); } diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/plugin/ShaderPlugin.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/plugin/ShaderPlugin.java new file mode 100644 index 00000000..81f5b7c7 --- /dev/null +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/plugin/ShaderPlugin.java @@ -0,0 +1,31 @@ +package com.github.penfeizhou.doric.plugin; + +import com.github.penfeizhou.doric.DoricContext; +import com.github.penfeizhou.doric.extension.bridge.DoricMethod; +import com.github.penfeizhou.doric.extension.bridge.DoricPlugin; +import com.github.penfeizhou.doric.utils.DoricLog; +import com.github.pengfeizhou.jscore.JSDecoder; +import com.github.pengfeizhou.jscore.JSObject; + +/** + * @Description: com.github.penfeizhou.doric.plugin + * @Author: pengfei.zhou + * @CreateDate: 2019-07-22 + */ +@DoricPlugin(name = "shader") +public class ShaderPlugin extends DoricJavaPlugin { + public ShaderPlugin(DoricContext doricContext) { + super(doricContext); + } + + @DoricMethod + public void render(JSDecoder jsDecoder) { + try { + JSObject jsObject = jsDecoder.decode().asObject(); + } catch (Exception e) { + e.printStackTrace(); + DoricLog.e("Shader.render:error%s", e.getLocalizedMessage()); + } + + } +} diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/utils/DoricUtils.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/utils/DoricUtils.java index 7970d3b8..c8c3c3a2 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/utils/DoricUtils.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/utils/DoricUtils.java @@ -10,6 +10,7 @@ import android.view.WindowManager; import com.github.penfeizhou.doric.Doric; import com.github.pengfeizhou.jscore.JSArray; import com.github.pengfeizhou.jscore.JSDecoder; +import com.github.pengfeizhou.jscore.JSONBuilder; import com.github.pengfeizhou.jscore.JSValue; import com.github.pengfeizhou.jscore.JavaValue; @@ -52,6 +53,8 @@ public class DoricUtils { public static JavaValue toJavaValue(Object arg) { if (arg == null) { return new JavaValue(); + } else if (arg instanceof JSONBuilder) { + return new JavaValue(((JSONBuilder) arg).toJSONObject()); } else if (arg instanceof JSONObject) { return new JavaValue((JSONObject) arg); } else if (arg instanceof String) { diff --git a/js-framework/demo.ts b/js-framework/demo.ts index 5b3ccecd..4756165a 100644 --- a/js-framework/demo.ts +++ b/js-framework/demo.ts @@ -1,12 +1,18 @@ import { NativeCall, Text, Alignment, Color, VLayout, Panel, log, logw, loge } from "./index" +import { Group } from "./src/ui/view"; @Entry export class MyPage extends Panel { - build() { - return new Text + + build(rootView: Group): void { + log('build view') + const text = new Text + text.text = "hello" + rootView.children.push(text) } + @NativeCall log() { log("Hello.HEGO") diff --git a/js-framework/rollup.config.js b/js-framework/rollup.config.js index d6947aa1..88d55597 100644 --- a/js-framework/rollup.config.js +++ b/js-framework/rollup.config.js @@ -26,6 +26,7 @@ export default [ plugins: [ resolve({ jsnext: true, main: true }), ], + external: ['reflect-metadata'] }, { input: "build/demo.js", diff --git a/js-framework/src/runtime/global.ts b/js-framework/src/runtime/global.ts index a17de6fc..ca77a600 100644 --- a/js-framework/src/runtime/global.ts +++ b/js-framework/src/runtime/global.ts @@ -1,5 +1,5 @@ import { Context } from "./sandbox"; -require('reflect-metadata'); +export * from 'reflect-metadata' declare global { const context: Context; diff --git a/js-framework/src/ui/panel.ts b/js-framework/src/ui/panel.ts index 658839b4..cbe3f372 100644 --- a/js-framework/src/ui/panel.ts +++ b/js-framework/src/ui/panel.ts @@ -1,6 +1,8 @@ -import { } from './../runtime/global'; +import './../runtime/global' import { View, Stack, Group } from "./view"; import { loge, log } from '../util/log'; +import { Model } from '../util/types'; +import { Context } from '../runtime/sandbox'; export function NativeCall(target: Panel, propertyKey: string, descriptor: PropertyDescriptor) { @@ -15,7 +17,7 @@ export function NativeCall(target: Panel, propertyKey: string, descriptor: Prope type Frame = { width: number, height: number } export abstract class Panel { - + context?: Context onCreate() { } onDestory() { } onShow() { } @@ -35,6 +37,7 @@ export abstract class Panel { @NativeCall private __init__(frame: Frame, data: any) { + log('__init__:', frame, data) this.__data__ = data this.__rootView__.width = frame.width this.__rootView__.height = frame.height @@ -88,15 +91,19 @@ export abstract class Panel { }, this.__rootView__) } + private nativeRender(model: Model) { + if (this.context) { + this.context.bridge.shader_render(model) + } + } + private hookBeforeNativeCall() { - log('__hookBeforeNativeCall__') } private hookAfterNativeCall() { - log('__hookAfterNativeCall__') if (this.__rootView__.isDirty()) { const model = this.__rootView__.toModel() - log('needRefresh:' + JSON.stringify(model)) + this.nativeRender(model) this.__rootView__.clean() } } diff --git a/js-framework/src/ui/view.ts b/js-framework/src/ui/view.ts index 6b21c836..3b54b08e 100644 --- a/js-framework/src/ui/view.ts +++ b/js-framework/src/ui/view.ts @@ -119,13 +119,13 @@ export abstract class View implements Modeling { clean() { for (const key in this.__dirty_props__) { - if (this.__dirty_props__.hasOwnProperty(key)) { - this.__dirty_props__[key] = undefined + if (Reflect.has(this.__dirty_props__, key)) { + Reflect.deleteProperty(this.__dirty_props__, key) } } } isDirty() { - return Reflect.ownKeys(this.__dirty_props__).length === 0 + return Reflect.ownKeys(this.__dirty_props__).length !== 0 } responseCallback(id: string, ...args: any) { const f = this.id2Callback(id)