begin render
This commit is contained in:
@@ -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<String, DoricJavaPlugin> 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;
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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();
|
||||
}
|
@@ -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<Object>() {
|
||||
@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());
|
||||
|
@@ -16,7 +16,7 @@ import java.util.Map;
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-20
|
||||
*/
|
||||
public abstract class GroupNode extends ViewNode<ViewGroup> {
|
||||
public abstract class GroupNode<F extends ViewGroup> extends ViewNode<F> {
|
||||
private Map<String, ViewNode> mChildrenNode = new HashMap<>();
|
||||
private SparseArray<ViewNode> mIndexInfo = new SparseArray<>();
|
||||
|
||||
|
@@ -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 <ImageView>{
|
||||
@DoricPlugin(name = "Image")
|
||||
public class ImageNode extends ViewNode<ImageView> {
|
||||
public ImageNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
|
@@ -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<FrameLayout> {
|
||||
public RootNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FrameLayout build(JSObject jsObject) {
|
||||
return new FrameLayout(getContext());
|
||||
}
|
||||
|
||||
public void setRootView(FrameLayout rootView) {
|
||||
this.mView = rootView;
|
||||
}
|
||||
}
|
@@ -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<FrameLayout> {
|
||||
public StackNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewGroup build(JSObject jsObject) {
|
||||
return null;
|
||||
public FrameLayout build(JSObject jsObject) {
|
||||
return new FrameLayout(getContext());
|
||||
}
|
||||
}
|
||||
|
@@ -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<TextView> {
|
||||
public TextNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
|
@@ -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<T extends View> 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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user