begin render

This commit is contained in:
pengfei.zhou 2019-07-22 15:38:30 +08:00
parent ed8b221288
commit 3bb2bae50c
15 changed files with 91 additions and 34 deletions

View File

@ -2,6 +2,7 @@ package com.github.penfeizhou.doricdemo;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.widget.FrameLayout;
import com.github.penfeizhou.doric.DoricContext; import com.github.penfeizhou.doric.DoricContext;
import com.github.penfeizhou.doric.utils.DoricUtils; 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 doricContext = DoricContext.create(this, DoricUtils.readAssetFile("demo.js"), "demo");
doricContext.callEntity("__init__", new JSONBuilder().put("width", 100).put("height", 100)); doricContext.callEntity("__init__", new JSONBuilder().put("width", 100).put("height", 100));
doricContext.callEntity("log"); doricContext.callEntity("log");
doricContext.getRootNode().setRootView((FrameLayout) findViewById(R.id.root));
} }
} }

View File

@ -15,4 +15,8 @@
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>

View File

@ -1,11 +1,16 @@
package com.github.penfeizhou.doric; package com.github.penfeizhou.doric;
import android.content.Context; import android.content.Context;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import com.github.penfeizhou.doric.async.AsyncResult; import com.github.penfeizhou.doric.async.AsyncResult;
import com.github.penfeizhou.doric.extension.render.DoricShader; import com.github.penfeizhou.doric.extension.render.DoricShader;
import com.github.penfeizhou.doric.plugin.DoricJavaPlugin; import com.github.penfeizhou.doric.plugin.DoricJavaPlugin;
import com.github.penfeizhou.doric.utils.DoricMetaInfo; 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 com.github.pengfeizhou.jscore.JSDecoder;
import java.util.HashMap; import java.util.HashMap;
@ -21,6 +26,7 @@ public class DoricContext {
private final Map<String, DoricJavaPlugin> mPluginMap = new HashMap<>(); private final Map<String, DoricJavaPlugin> mPluginMap = new HashMap<>();
private final Context mContext; private final Context mContext;
private DoricShader doricShader = new DoricShader(getDriver().getRegistry()); private DoricShader doricShader = new DoricShader(getDriver().getRegistry());
private RootNode mRootNode = new RootNode(this);
DoricContext(Context context, String contextId) { DoricContext(Context context, String contextId) {
this.mContext = context; this.mContext = context;
@ -39,6 +45,10 @@ public class DoricContext {
return DoricDriver.getInstance(); return DoricDriver.getInstance();
} }
public RootNode getRootNode() {
return mRootNode;
}
public Context getContext() { public Context getContext() {
return mContext; return mContext;
} }

View File

@ -3,6 +3,10 @@ package com.github.penfeizhou.doric;
import android.text.TextUtils; import android.text.TextUtils;
import com.github.penfeizhou.doric.plugin.ShaderPlugin; 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.widget.ViewNode;
import com.github.penfeizhou.doric.utils.DoricMetaInfo; import com.github.penfeizhou.doric.utils.DoricMetaInfo;
import com.github.penfeizhou.doric.plugin.DoricJavaPlugin; import com.github.penfeizhou.doric.plugin.DoricJavaPlugin;
@ -39,6 +43,10 @@ public class DoricRegistry {
public DoricRegistry() { public DoricRegistry() {
this.registerNativePlugin(ShaderPlugin.class); this.registerNativePlugin(ShaderPlugin.class);
this.registerNativePlugin(ModalPlugin.class); this.registerNativePlugin(ModalPlugin.class);
this.registerViewNode(RootNode.class);
this.registerViewNode(TextNode.class);
this.registerViewNode(ImageNode.class);
this.registerViewNode(StackNode.class);
initRegistry(this); initRegistry(this);
} }

View File

@ -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();
}

View File

@ -1,12 +1,19 @@
package com.github.penfeizhou.doric.plugin; package com.github.penfeizhou.doric.plugin;
import android.view.ViewGroup;
import com.github.penfeizhou.doric.DoricContext; import com.github.penfeizhou.doric.DoricContext;
import com.github.penfeizhou.doric.extension.bridge.DoricMethod; import com.github.penfeizhou.doric.extension.bridge.DoricMethod;
import com.github.penfeizhou.doric.extension.bridge.DoricPlugin; import com.github.penfeizhou.doric.extension.bridge.DoricPlugin;
import com.github.penfeizhou.doric.utils.DoricLog; 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.JSDecoder;
import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSObject;
import java.util.concurrent.Callable;
/** /**
* @Description: com.github.penfeizhou.doric.plugin * @Description: com.github.penfeizhou.doric.plugin
* @Author: pengfei.zhou * @Author: pengfei.zhou
@ -21,7 +28,15 @@ public class ShaderPlugin extends DoricJavaPlugin {
@DoricMethod @DoricMethod
public void render(JSDecoder jsDecoder) { public void render(JSDecoder jsDecoder) {
try { 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) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
DoricLog.e("Shader.render:error%s", e.getLocalizedMessage()); DoricLog.e("Shader.render:error%s", e.getLocalizedMessage());

View File

@ -16,7 +16,7 @@ import java.util.Map;
* @Author: pengfei.zhou * @Author: pengfei.zhou
* @CreateDate: 2019-07-20 * @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 Map<String, ViewNode> mChildrenNode = new HashMap<>();
private SparseArray<ViewNode> mIndexInfo = new SparseArray<>(); private SparseArray<ViewNode> mIndexInfo = new SparseArray<>();

View File

@ -3,7 +3,7 @@ package com.github.penfeizhou.doric.widget;
import android.widget.ImageView; import android.widget.ImageView;
import com.github.penfeizhou.doric.DoricContext; 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; import com.github.pengfeizhou.jscore.JSObject;
/** /**
@ -11,8 +11,8 @@ import com.github.pengfeizhou.jscore.JSObject;
* @Author: pengfei.zhou * @Author: pengfei.zhou
* @CreateDate: 2019-07-20 * @CreateDate: 2019-07-20
*/ */
@DoricNode(name = "Image") @DoricPlugin(name = "Image")
public class ImageNode extends ViewNode <ImageView>{ public class ImageNode extends ViewNode<ImageView> {
public ImageNode(DoricContext doricContext) { public ImageNode(DoricContext doricContext) {
super(doricContext); super(doricContext);
} }

View File

@ -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;
}
}

View File

@ -1,8 +1,9 @@
package com.github.penfeizhou.doric.widget; 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.DoricContext;
import com.github.penfeizhou.doric.extension.bridge.DoricPlugin;
import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSObject;
/** /**
@ -10,13 +11,14 @@ import com.github.pengfeizhou.jscore.JSObject;
* @Author: pengfei.zhou * @Author: pengfei.zhou
* @CreateDate: 2019-07-20 * @CreateDate: 2019-07-20
*/ */
public class StackNode extends GroupNode { @DoricPlugin(name = "Stack")
public class StackNode extends GroupNode<FrameLayout> {
public StackNode(DoricContext doricContext) { public StackNode(DoricContext doricContext) {
super(doricContext); super(doricContext);
} }
@Override @Override
public ViewGroup build(JSObject jsObject) { public FrameLayout build(JSObject jsObject) {
return null; return new FrameLayout(getContext());
} }
} }

View File

@ -3,7 +3,7 @@ package com.github.penfeizhou.doric.widget;
import android.widget.TextView; import android.widget.TextView;
import com.github.penfeizhou.doric.DoricContext; 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; import com.github.pengfeizhou.jscore.JSObject;
/** /**
@ -11,7 +11,7 @@ import com.github.pengfeizhou.jscore.JSObject;
* @Author: pengfei.zhou * @Author: pengfei.zhou
* @CreateDate: 2019-07-20 * @CreateDate: 2019-07-20
*/ */
@DoricNode(name = "Text") @DoricPlugin(name = "Text")
public class TextNode extends ViewNode<TextView> { public class TextNode extends ViewNode<TextView> {
public TextNode(DoricContext doricContext) { public TextNode(DoricContext doricContext) {
super(doricContext); super(doricContext);

View File

@ -13,8 +13,6 @@ import com.github.penfeizhou.doric.utils.DoricUtils;
import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
/** /**
* @Description: Render * @Description: Render
@ -45,6 +43,11 @@ public abstract class ViewNode<T extends View> extends DoricComponent {
if (mView == null) { if (mView == null) {
mView = build(jsObject); mView = build(jsObject);
} }
if (mView.getLayoutParams() == null) {
mView.setLayoutParams(new ViewGroup.MarginLayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
}
setFrame(mView.getLayoutParams(), jsObject); setFrame(mView.getLayoutParams(), jsObject);
} }

View File

@ -11,6 +11,7 @@ export class MyPage extends Panel {
const text = new Text const text = new Text
text.text = "hello" text.text = "hello"
rootView.children.push(text) rootView.children.push(text)
rootView.bgColor = Color.safeParse('#00ff00')
} }
@NativeCall @NativeCall

View File

@ -1,5 +1,5 @@
import './../runtime/global' import './../runtime/global'
import { View, Stack, Group } from "./view"; import { View, Group, Root } from "./view";
import { loge, log } from '../util/log'; import { loge, log } from '../util/log';
import { Model } from '../util/types'; import { Model } from '../util/types';
@ -25,7 +25,7 @@ export abstract class Panel {
abstract build(rootView: Group): void abstract build(rootView: Group): void
private __data__: any private __data__: any
private __rootView__: Group = new Stack private __rootView__ = new Root
getRootView() { getRootView() {
return this.__rootView__ return this.__rootView__

View File

@ -235,7 +235,9 @@ export class Stack extends Group {
@Property @Property
gravity?: number gravity?: number
} }
export class Root extends Stack {
}
class LinearLayout extends Group { class LinearLayout extends Group {
@Property @Property
space?: number space?: number