From 3bb2bae50c9bb73b5aaa37862e03d1469bdf0cdf Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Mon, 22 Jul 2019 15:38:30 +0800 Subject: [PATCH] begin render --- .../penfeizhou/doricdemo/MainActivity.java | 2 ++ .../app/src/main/res/layout/activity_main.xml | 4 +++ .../github/penfeizhou/doric/DoricContext.java | 10 +++++++ .../penfeizhou/doric/DoricRegistry.java | 8 +++++ .../doric/extension/render/DoricNode.java | 19 ------------ .../penfeizhou/doric/plugin/ShaderPlugin.java | 17 ++++++++++- .../penfeizhou/doric/widget/GroupNode.java | 2 +- .../penfeizhou/doric/widget/ImageNode.java | 6 ++-- .../penfeizhou/doric/widget/RootNode.java | 29 +++++++++++++++++++ .../penfeizhou/doric/widget/StackNode.java | 10 ++++--- .../penfeizhou/doric/widget/TextNode.java | 4 +-- .../penfeizhou/doric/widget/ViewNode.java | 7 +++-- js-framework/demo.ts | 1 + js-framework/src/ui/panel.ts | 4 +-- js-framework/src/ui/view.ts | 2 ++ 15 files changed, 91 insertions(+), 34 deletions(-) delete mode 100644 Android/doric/src/main/java/com/github/penfeizhou/doric/extension/render/DoricNode.java create mode 100644 Android/doric/src/main/java/com/github/penfeizhou/doric/widget/RootNode.java 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 2cf16a8b..6918a85f 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 @@ -2,6 +2,7 @@ package com.github.penfeizhou.doricdemo; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.widget.FrameLayout; import com.github.penfeizhou.doric.DoricContext; import com.github.penfeizhou.doric.utils.DoricUtils; @@ -16,5 +17,6 @@ public class MainActivity extends AppCompatActivity { DoricContext doricContext = DoricContext.create(this, DoricUtils.readAssetFile("demo.js"), "demo"); doricContext.callEntity("__init__", new JSONBuilder().put("width", 100).put("height", 100)); doricContext.callEntity("log"); + doricContext.getRootNode().setRootView((FrameLayout) findViewById(R.id.root)); } } diff --git a/Android/app/src/main/res/layout/activity_main.xml b/Android/app/src/main/res/layout/activity_main.xml index c4d9f0f3..04dce6cd 100644 --- a/Android/app/src/main/res/layout/activity_main.xml +++ b/Android/app/src/main/res/layout/activity_main.xml @@ -15,4 +15,8 @@ app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> + \ No newline at end of file diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/DoricContext.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/DoricContext.java index 1a5d7274..72fba673 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/DoricContext.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/DoricContext.java @@ -1,11 +1,16 @@ package com.github.penfeizhou.doric; import android.content.Context; +import android.view.ViewGroup; +import android.widget.FrameLayout; import com.github.penfeizhou.doric.async.AsyncResult; import com.github.penfeizhou.doric.extension.render.DoricShader; import com.github.penfeizhou.doric.plugin.DoricJavaPlugin; import com.github.penfeizhou.doric.utils.DoricMetaInfo; +import com.github.penfeizhou.doric.widget.GroupNode; +import com.github.penfeizhou.doric.widget.RootNode; +import com.github.penfeizhou.doric.widget.StackNode; import com.github.pengfeizhou.jscore.JSDecoder; import java.util.HashMap; @@ -21,6 +26,7 @@ public class DoricContext { private final Map mPluginMap = new HashMap<>(); private final Context mContext; private DoricShader doricShader = new DoricShader(getDriver().getRegistry()); + private RootNode mRootNode = new RootNode(this); DoricContext(Context context, String contextId) { this.mContext = context; @@ -39,6 +45,10 @@ public class DoricContext { return DoricDriver.getInstance(); } + public RootNode getRootNode() { + return mRootNode; + } + public Context getContext() { return mContext; } 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 9d28589a..b5af1d17 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 @@ -3,6 +3,10 @@ package com.github.penfeizhou.doric; import android.text.TextUtils; import com.github.penfeizhou.doric.plugin.ShaderPlugin; +import com.github.penfeizhou.doric.widget.ImageNode; +import com.github.penfeizhou.doric.widget.RootNode; +import com.github.penfeizhou.doric.widget.StackNode; +import com.github.penfeizhou.doric.widget.TextNode; import com.github.penfeizhou.doric.widget.ViewNode; import com.github.penfeizhou.doric.utils.DoricMetaInfo; import com.github.penfeizhou.doric.plugin.DoricJavaPlugin; @@ -39,6 +43,10 @@ public class DoricRegistry { public DoricRegistry() { this.registerNativePlugin(ShaderPlugin.class); this.registerNativePlugin(ModalPlugin.class); + this.registerViewNode(RootNode.class); + this.registerViewNode(TextNode.class); + this.registerViewNode(ImageNode.class); + this.registerViewNode(StackNode.class); initRegistry(this); } diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/extension/render/DoricNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/extension/render/DoricNode.java deleted file mode 100644 index 4e119a56..00000000 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/extension/render/DoricNode.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.penfeizhou.doric.extension.render; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * @Description: com.github.penfeizhou.doric.render - * @Author: pengfei.zhou - * @CreateDate: 2019-07-20 - */ -@Documented -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -public @interface DoricNode { - String name(); -} \ No newline at end of file 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 index 81f5b7c7..8386b56e 100644 --- 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 @@ -1,12 +1,19 @@ package com.github.penfeizhou.doric.plugin; +import android.view.ViewGroup; + 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.penfeizhou.doric.utils.ThreadMode; +import com.github.penfeizhou.doric.widget.GroupNode; +import com.github.penfeizhou.doric.widget.RootNode; import com.github.pengfeizhou.jscore.JSDecoder; import com.github.pengfeizhou.jscore.JSObject; +import java.util.concurrent.Callable; + /** * @Description: com.github.penfeizhou.doric.plugin * @Author: pengfei.zhou @@ -21,7 +28,15 @@ public class ShaderPlugin extends DoricJavaPlugin { @DoricMethod public void render(JSDecoder jsDecoder) { try { - JSObject jsObject = jsDecoder.decode().asObject(); + final JSObject jsObject = jsDecoder.decode().asObject(); + getDoricContext().getDriver().asyncCall(new Callable() { + @Override + public Object call() throws Exception { + RootNode rootNode = getDoricContext().getRootNode(); + rootNode.blend(jsObject.getProperty("props").asObject()); + return null; + } + }, ThreadMode.UI); } 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/widget/GroupNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/GroupNode.java index 83c66a26..d6453ded 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/GroupNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/GroupNode.java @@ -16,7 +16,7 @@ import java.util.Map; * @Author: pengfei.zhou * @CreateDate: 2019-07-20 */ -public abstract class GroupNode extends ViewNode { +public abstract class GroupNode extends ViewNode { private Map mChildrenNode = new HashMap<>(); private SparseArray mIndexInfo = new SparseArray<>(); diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/ImageNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/ImageNode.java index 36918c52..bf92341e 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/ImageNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/ImageNode.java @@ -3,7 +3,7 @@ package com.github.penfeizhou.doric.widget; import android.widget.ImageView; import com.github.penfeizhou.doric.DoricContext; -import com.github.penfeizhou.doric.extension.render.DoricNode; +import com.github.penfeizhou.doric.extension.bridge.DoricPlugin; import com.github.pengfeizhou.jscore.JSObject; /** @@ -11,8 +11,8 @@ import com.github.pengfeizhou.jscore.JSObject; * @Author: pengfei.zhou * @CreateDate: 2019-07-20 */ -@DoricNode(name = "Image") -public class ImageNode extends ViewNode { +@DoricPlugin(name = "Image") +public class ImageNode extends ViewNode { public ImageNode(DoricContext doricContext) { super(doricContext); } diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/RootNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/RootNode.java new file mode 100644 index 00000000..dd3a6527 --- /dev/null +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/RootNode.java @@ -0,0 +1,29 @@ +package com.github.penfeizhou.doric.widget; + +import android.view.ViewGroup; +import android.widget.FrameLayout; + +import com.github.penfeizhou.doric.DoricContext; +import com.github.penfeizhou.doric.extension.bridge.DoricPlugin; +import com.github.pengfeizhou.jscore.JSObject; + +/** + * @Description: com.github.penfeizhou.doric.widget + * @Author: pengfei.zhou + * @CreateDate: 2019-07-20 + */ +@DoricPlugin(name = "Root") +public class RootNode extends GroupNode { + public RootNode(DoricContext doricContext) { + super(doricContext); + } + + @Override + public FrameLayout build(JSObject jsObject) { + return new FrameLayout(getContext()); + } + + public void setRootView(FrameLayout rootView) { + this.mView = rootView; + } +} diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/StackNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/StackNode.java index f281ce9c..175a5a16 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/StackNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/StackNode.java @@ -1,8 +1,9 @@ package com.github.penfeizhou.doric.widget; -import android.view.ViewGroup; +import android.widget.FrameLayout; import com.github.penfeizhou.doric.DoricContext; +import com.github.penfeizhou.doric.extension.bridge.DoricPlugin; import com.github.pengfeizhou.jscore.JSObject; /** @@ -10,13 +11,14 @@ import com.github.pengfeizhou.jscore.JSObject; * @Author: pengfei.zhou * @CreateDate: 2019-07-20 */ -public class StackNode extends GroupNode { +@DoricPlugin(name = "Stack") +public class StackNode extends GroupNode { public StackNode(DoricContext doricContext) { super(doricContext); } @Override - public ViewGroup build(JSObject jsObject) { - return null; + public FrameLayout build(JSObject jsObject) { + return new FrameLayout(getContext()); } } diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/TextNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/TextNode.java index 0352cb54..753ed266 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/TextNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/TextNode.java @@ -3,7 +3,7 @@ package com.github.penfeizhou.doric.widget; import android.widget.TextView; import com.github.penfeizhou.doric.DoricContext; -import com.github.penfeizhou.doric.extension.render.DoricNode; +import com.github.penfeizhou.doric.extension.bridge.DoricPlugin; import com.github.pengfeizhou.jscore.JSObject; /** @@ -11,7 +11,7 @@ import com.github.pengfeizhou.jscore.JSObject; * @Author: pengfei.zhou * @CreateDate: 2019-07-20 */ -@DoricNode(name = "Text") +@DoricPlugin(name = "Text") public class TextNode extends ViewNode { public TextNode(DoricContext doricContext) { super(doricContext); diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/ViewNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/ViewNode.java index 677474c6..70932d3f 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/ViewNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/ViewNode.java @@ -13,8 +13,6 @@ import com.github.penfeizhou.doric.utils.DoricUtils; import com.github.pengfeizhou.jscore.JSObject; import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; /** * @Description: Render @@ -45,6 +43,11 @@ public abstract class ViewNode extends DoricComponent { if (mView == null) { mView = build(jsObject); } + if (mView.getLayoutParams() == null) { + mView.setLayoutParams(new ViewGroup.MarginLayoutParams( + ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT)); + } setFrame(mView.getLayoutParams(), jsObject); } diff --git a/js-framework/demo.ts b/js-framework/demo.ts index f6fa32d7..6695eb0f 100644 --- a/js-framework/demo.ts +++ b/js-framework/demo.ts @@ -11,6 +11,7 @@ export class MyPage extends Panel { const text = new Text text.text = "hello" rootView.children.push(text) + rootView.bgColor = Color.safeParse('#00ff00') } @NativeCall diff --git a/js-framework/src/ui/panel.ts b/js-framework/src/ui/panel.ts index 592c71f5..306449ba 100644 --- a/js-framework/src/ui/panel.ts +++ b/js-framework/src/ui/panel.ts @@ -1,5 +1,5 @@ import './../runtime/global' -import { View, Stack, Group } from "./view"; +import { View, Group, Root } from "./view"; import { loge, log } from '../util/log'; import { Model } from '../util/types'; @@ -25,7 +25,7 @@ export abstract class Panel { abstract build(rootView: Group): void private __data__: any - private __rootView__: Group = new Stack + private __rootView__ = new Root getRootView() { return this.__rootView__ diff --git a/js-framework/src/ui/view.ts b/js-framework/src/ui/view.ts index 3b54b08e..184ac3ee 100644 --- a/js-framework/src/ui/view.ts +++ b/js-framework/src/ui/view.ts @@ -235,7 +235,9 @@ export class Stack extends Group { @Property gravity?: number } +export class Root extends Stack { +} class LinearLayout extends Group { @Property space?: number