diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/DoricLayer.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/DoricLayer.java new file mode 100644 index 00000000..8278c3b8 --- /dev/null +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/DoricLayer.java @@ -0,0 +1,76 @@ +package com.github.penfeizhou.doric.shader; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.Region; +import android.os.Build; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.RequiresApi; +import android.util.AttributeSet; +import android.view.View; +import android.widget.FrameLayout; + +/** + * @Description: com.github.penfeizhou.doric.shader + * @Author: pengfei.zhou + * @CreateDate: 2019-07-31 + */ +public class DoricLayer extends FrameLayout { + private int mBorderWidth; + private int mBorderColor = Color.BLACK; + private int mCornerRadius; + + private Path mCornerPath = new Path(); + private Paint shadowPaint = new Paint(); + + + public DoricLayer(@NonNull Context context) { + super(context); + } + + public DoricLayer(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + public DoricLayer(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + public DoricLayer(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + // draw shadow + canvas.save(); + canvas.restore(); + } + + @Override + protected boolean drawChild(Canvas canvas, View child, long drawingTime) { + return super.drawChild(canvas, child, drawingTime); + } + + public void setBorderWidth(int borderWidth) { + this.mBorderWidth = borderWidth; + } + + public void setBorderColor(int borderColor) { + this.mBorderColor = borderColor; + } + + public void setCornerRadius(int corner) { + if (mCornerRadius != corner) { + this.mCornerRadius = corner; + mCornerPath.reset(); + } + } + +} diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/GroupNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/GroupNode.java index 2fdef5a3..173b68a5 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/GroupNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/GroupNode.java @@ -50,7 +50,7 @@ public abstract class GroupNode extends ViewNode { } else if (i != child.index) { mIndexInfo.remove(i); child.index = i; - mView.removeView(child.mView); + mView.removeView(child.getView()); } ViewGroup.LayoutParams params = child.getLayoutParams(); if (params == null) { @@ -58,7 +58,7 @@ public abstract class GroupNode extends ViewNode { } child.blend(childObj.getProperty("props").asObject(), params); if (mIndexInfo.get(i) == null) { - mView.addView(child.mView, i); + mView.addView(child.getView(), i, child.getLayoutParams()); mIndexInfo.put(i, child); } } diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/RootNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/RootNode.java index 873c8eba..cd67271e 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/RootNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/RootNode.java @@ -1,5 +1,7 @@ package com.github.penfeizhou.doric.shader; +import android.view.View; +import android.view.ViewGroup; import android.widget.FrameLayout; import com.github.penfeizhou.doric.DoricContext; @@ -17,11 +19,21 @@ public class RootNode extends StackNode { super(doricContext); } + @Override + public View getView() { + return mView; + } + public void setRootView(FrameLayout rootView) { this.mView = rootView; } + @Override + public ViewGroup.LayoutParams getLayoutParams() { + return mView.getLayoutParams(); + } + public void render(JSObject props) { - blend(props, mView.getLayoutParams()); + blend(props, getLayoutParams()); } } diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/ViewNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/ViewNode.java index 1071493f..c392b9cc 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/ViewNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/ViewNode.java @@ -3,6 +3,7 @@ package com.github.penfeizhou.doric.shader; import android.content.Context; import android.view.View; import android.view.ViewGroup; +import android.widget.FrameLayout; import com.github.penfeizhou.doric.DoricContext; import com.github.penfeizhou.doric.DoricRegistry; @@ -31,8 +32,10 @@ public abstract class ViewNode extends DoricContextHolder { super(doricContext); } - public T getView() { - return mView; + private DoricLayer doricLayer; + + public View getView() { + return doricLayer; } public Context getContext() { @@ -49,7 +52,16 @@ public abstract class ViewNode extends DoricContextHolder { for (String prop : jsObject.propertySet()) { blend(mView, layoutParams, prop, jsObject.getProperty(prop)); } - mView.setLayoutParams(layoutParams); + if (getView() == null) { + doricLayer = new DoricLayer(getContext()); + FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(layoutParams.width, layoutParams.height); + doricLayer.addView(mView, params); + } else { + ViewGroup.LayoutParams params = mView.getLayoutParams(); + params.width = layoutParams.width; + params.height = layoutParams.height; + mView.setLayoutParams(params); + } } protected void blend(T view, ViewGroup.LayoutParams layoutParams, String name, JSValue prop) { diff --git a/js-framework/demo.ts b/js-framework/demo.ts index e9503a91..f35e4add 100644 --- a/js-framework/demo.ts +++ b/js-framework/demo.ts @@ -174,7 +174,7 @@ class SnakeModel { if (this.head.x < 0 || this.head.x >= this.width || this.head.y < 0 || this.head.y >= this.height) { //If out of bound - loge('out of bound', this.head) + loge('out of bound') this.state = State.fail } else if (this.head.x == this.food.x && this.head.y == this.food.y) { //If eat food