add shader plugin
This commit is contained in:
parent
6b0b98a0ad
commit
b73312d1e4
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
@ -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")
|
||||
|
@ -26,6 +26,7 @@ export default [
|
||||
plugins: [
|
||||
resolve({ jsnext: true, main: true }),
|
||||
],
|
||||
external: ['reflect-metadata']
|
||||
},
|
||||
{
|
||||
input: "build/demo.js",
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Context } from "./sandbox";
|
||||
require('reflect-metadata');
|
||||
export * from 'reflect-metadata'
|
||||
|
||||
declare global {
|
||||
const context: Context;
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user