diff --git a/doric-android/doric/src/main/java/pub/doric/refresh/RefreshableNode.java b/doric-android/doric/src/main/java/pub/doric/refresh/RefreshableNode.java index a073803b..d2d8ce21 100644 --- a/doric-android/doric/src/main/java/pub/doric/refresh/RefreshableNode.java +++ b/doric-android/doric/src/main/java/pub/doric/refresh/RefreshableNode.java @@ -40,10 +40,19 @@ public class RefreshableNode extends SuperNode implements Pull @Override protected void blend(DoricSwipeLayout view, String name, JSValue prop) { if ("content".equals(name)) { + if (!prop.isString()) { + return; + } mContentViewId = prop.asString().value(); } else if ("header".equals(name)) { + if (!prop.isString()) { + return; + } mHeaderViewId = prop.asString().value(); } else if ("onRefresh".equals(name)) { + if (!prop.isString()) { + return; + } final String funcId = prop.asString().value(); mView.setOnRefreshListener(new DoricSwipeLayout.OnRefreshListener() { @Override diff --git a/doric-android/doric/src/main/java/pub/doric/shader/ImageNode.java b/doric-android/doric/src/main/java/pub/doric/shader/ImageNode.java index 94c07436..3e43203f 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/ImageNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/ImageNode.java @@ -66,7 +66,7 @@ public class ImageNode extends ViewNode { @Override protected ImageView build() { - ImageView imageView = new ImageView(getContext()); + ImageView imageView = new ImageView(getContext()); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); return imageView; } @@ -188,6 +188,9 @@ public class ImageNode extends ViewNode { protected void blend(ImageView view, String name, JSValue prop) { switch (name) { case "imageUrl": + if (!prop.isString()) { + return; + } loadImageUrl(prop.asString().value()); break; case "scaleType": @@ -208,6 +211,9 @@ public class ImageNode extends ViewNode { this.loadCallbackId = prop.asString().value(); break; case "imageBase64": + if (!prop.isString()) { + return; + } Pattern r = Pattern.compile("data:image/(\\S+?);base64,(\\S+)"); Matcher m = r.matcher(prop.asString().value()); if (m.find()) { @@ -225,10 +231,16 @@ public class ImageNode extends ViewNode { } break; case "imagePath": + if (!prop.isString()) { + return; + } String localName = prop.asString().value(); loadImageUrl("file:///android_asset/" + localName); break; case "imageRes": + if (!prop.isString()) { + return; + } int resId = getContext().getResources().getIdentifier( prop.asString().value().toLowerCase(), "drawable", diff --git a/doric-android/doric/src/main/java/pub/doric/shader/LinearNode.java b/doric-android/doric/src/main/java/pub/doric/shader/LinearNode.java index 078ebf4d..d35a8a4e 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/LinearNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/LinearNode.java @@ -62,6 +62,9 @@ public class LinearNode extends GroupNode { protected void blend(LinearLayout view, String name, JSValue prop) { switch (name) { case "space": + if (!prop.isNumber()) { + return; + } ShapeDrawable shapeDrawable; if (view.getDividerDrawable() == null) { shapeDrawable = new ShapeDrawable(); @@ -79,6 +82,9 @@ public class LinearNode extends GroupNode { view.setDividerDrawable(shapeDrawable); break; case "gravity": + if (!prop.isNumber()) { + return; + } view.setGravity(prop.asNumber().toInt()); break; default: diff --git a/doric-android/doric/src/main/java/pub/doric/shader/ScrollerNode.java b/doric-android/doric/src/main/java/pub/doric/shader/ScrollerNode.java index a648fd23..5472d176 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/ScrollerNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/ScrollerNode.java @@ -99,10 +99,19 @@ public class ScrollerNode extends SuperNode implements IDoricScrol @Override protected void blend(HVScrollView view, String name, JSValue prop) { if ("content".equals(name)) { + if (!prop.isString()) { + return; + } mChildViewId = prop.asString().value(); } else if ("onScroll".equals(name)) { + if (!prop.isString()) { + return; + } onScrollFuncId = prop.asString().value(); } else if ("onScrollEnd".equals(name)) { + if (!prop.isString()) { + return; + } onScrollEndFuncId = prop.asString().value(); } else { super.blend(view, name, prop); diff --git a/doric-android/doric/src/main/java/pub/doric/shader/SwitchNode.java b/doric-android/doric/src/main/java/pub/doric/shader/SwitchNode.java index c03920f6..f3c60864 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/SwitchNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/SwitchNode.java @@ -52,9 +52,15 @@ public class SwitchNode extends ViewNode { protected void blend(SwitchCompat view, String name, JSValue prop) { switch (name) { case "state": + if (!prop.isBoolean()) { + return; + } view.setChecked(prop.asBoolean().value()); break; case "onSwitch": + if (!prop.isString()) { + return; + } final String callbackId = prop.asString().value(); view.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override @@ -64,12 +70,21 @@ public class SwitchNode extends ViewNode { }); break; case "offTintColor": + if (!prop.isNumber()) { + return; + } this.offTintColor = prop.asNumber().toInt(); break; case "onTintColor": + if (!prop.isNumber()) { + return; + } this.onTintColor = prop.asNumber().toInt(); break; case "thumbTintColor": + if (!prop.isNumber()) { + return; + } this.thumbTintColor = prop.asNumber().toInt(); break; default: diff --git a/doric-android/doric/src/main/java/pub/doric/shader/TextNode.java b/doric-android/doric/src/main/java/pub/doric/shader/TextNode.java index a75bf2bf..d45cb1f3 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/TextNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/TextNode.java @@ -23,7 +23,6 @@ import android.widget.TextView; import com.github.pengfeizhou.jscore.JSValue; -import pub.doric.Doric; import pub.doric.DoricContext; import pub.doric.extension.bridge.DoricPlugin; import pub.doric.utils.DoricUtils; @@ -52,16 +51,27 @@ public class TextNode extends ViewNode { protected void blend(TextView view, String name, JSValue prop) { switch (name) { case "text": - view.setLineSpacing(0, 1); + if (!prop.isString()) { + return; + } view.setText(prop.asString().toString()); break; case "textSize": + if (!prop.isNumber()) { + return; + } view.setTextSize(TypedValue.COMPLEX_UNIT_DIP, prop.asNumber().toFloat()); break; case "textColor": + if (!prop.isNumber()) { + return; + } view.setTextColor(prop.asNumber().toInt()); break; case "textAlignment": + if (!prop.isNumber()) { + return; + } view.setGravity(prop.asNumber().toInt() | Gravity.CENTER_VERTICAL); break; case "maxLines": @@ -87,6 +97,9 @@ public class TextNode extends ViewNode { } break; case "font": + if (!prop.isString()) { + return; + } String font = prop.asString().toString(); if (font.endsWith(".ttf")) { Typeface iconFont = Typeface.createFromAsset(getContext().getAssets(), font); @@ -98,12 +111,21 @@ public class TextNode extends ViewNode { break; case "maxWidth": + if (!prop.isNumber()) { + return; + } view.setMaxWidth(DoricUtils.dp2px(prop.asNumber().toFloat())); break; case "maxHeight": + if (!prop.isNumber()) { + return; + } view.setMaxHeight(DoricUtils.dp2px(prop.asNumber().toFloat())); break; case "lineSpacing": + if (!prop.isNumber()) { + return; + } view.setLineSpacing(DoricUtils.dp2px(prop.asNumber().toFloat()), 1); break; default: diff --git a/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java b/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java index 2c642446..13d0b6bb 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java @@ -148,6 +148,9 @@ public abstract class ViewNode extends DoricContextHolder { protected void blend(T view, String name, JSValue prop) { switch (name) { case "width": + if (!prop.isNumber()) { + return; + } if (isAnimating()) { addAnimator(ObjectAnimator.ofFloat( this, @@ -159,6 +162,9 @@ public abstract class ViewNode extends DoricContextHolder { } break; case "height": + if (!prop.isNumber()) { + return; + } if (isAnimating()) { addAnimator(ObjectAnimator.ofFloat( this, @@ -170,6 +176,9 @@ public abstract class ViewNode extends DoricContextHolder { } break; case "x": + if (!prop.isNumber()) { + return; + } if (isAnimating()) { addAnimator(ObjectAnimator.ofFloat( this, @@ -181,6 +190,9 @@ public abstract class ViewNode extends DoricContextHolder { } break; case "y": + if (!prop.isNumber()) { + return; + } if (isAnimating()) { addAnimator(ObjectAnimator.ofFloat( this, @@ -248,6 +260,9 @@ public abstract class ViewNode extends DoricContextHolder { } break; case "onClick": + if (!prop.isString()) { + return; + } final String functionId = prop.asString().value(); view.setOnClickListener(new View.OnClickListener() { @Override @@ -264,6 +279,9 @@ public abstract class ViewNode extends DoricContextHolder { } break; case "alpha": + if (!prop.isNumber()) { + return; + } if (isAnimating()) { addAnimator(ObjectAnimator.ofFloat( this, @@ -310,6 +328,9 @@ public abstract class ViewNode extends DoricContextHolder { } break; case "translationX": + if (!prop.isNumber()) { + return; + } if (isAnimating()) { addAnimator(ObjectAnimator.ofFloat( this, @@ -321,6 +342,9 @@ public abstract class ViewNode extends DoricContextHolder { } break; case "translationY": + if (!prop.isNumber()) { + return; + } if (isAnimating()) { addAnimator(ObjectAnimator.ofFloat( this, @@ -332,6 +356,9 @@ public abstract class ViewNode extends DoricContextHolder { } break; case "scaleX": + if (!prop.isNumber()) { + return; + } if (isAnimating()) { addAnimator(ObjectAnimator.ofFloat( this, @@ -343,6 +370,9 @@ public abstract class ViewNode extends DoricContextHolder { } break; case "scaleY": + if (!prop.isNumber()) { + return; + } if (isAnimating()) { addAnimator(ObjectAnimator.ofFloat( this, @@ -354,6 +384,9 @@ public abstract class ViewNode extends DoricContextHolder { } break; case "pivotX": + if (!prop.isNumber()) { + return; + } if (isAnimating()) { addAnimator(ObjectAnimator.ofFloat( this, @@ -365,6 +398,9 @@ public abstract class ViewNode extends DoricContextHolder { } break; case "pivotY": + if (!prop.isNumber()) { + return; + } if (isAnimating()) { addAnimator(ObjectAnimator.ofFloat( this, @@ -376,6 +412,9 @@ public abstract class ViewNode extends DoricContextHolder { } break; case "rotation": + if (!prop.isNumber()) { + return; + } if (isAnimating()) { addAnimator(ObjectAnimator.ofFloat( this, diff --git a/doric-android/doric/src/main/java/pub/doric/shader/flowlayout/FlowLayoutNode.java b/doric-android/doric/src/main/java/pub/doric/shader/flowlayout/FlowLayoutNode.java index bb59c53e..84fa62a1 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/flowlayout/FlowLayoutNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/flowlayout/FlowLayoutNode.java @@ -113,18 +113,33 @@ public class FlowLayoutNode extends SuperNode implements IDoricScr protected void blend(RecyclerView view, String name, JSValue prop) { switch (name) { case "columnSpace": + if (!prop.isNumber()) { + return; + } columnSpace = DoricUtils.dp2px(prop.asNumber().toFloat()); break; case "rowSpace": + if (!prop.isNumber()) { + return; + } rowSpace = DoricUtils.dp2px(prop.asNumber().toFloat()); break; case "columnCount": + if (!prop.isNumber()) { + return; + } staggeredGridLayoutManager.setSpanCount(prop.asNumber().toInt()); break; case "itemCount": + if (!prop.isNumber()) { + return; + } this.flowAdapter.itemCount = prop.asNumber().toInt(); break; case "renderItem": + if (!prop.isString()) { + return; + } String funcId = prop.asString().value(); if (!funcId.equals(this.flowAdapter.renderItemFuncId)) { this.flowAdapter.renderItemFuncId = funcId; @@ -136,21 +151,39 @@ public class FlowLayoutNode extends SuperNode implements IDoricScr } break; case "batchCount": + if (!prop.isNumber()) { + return; + } this.flowAdapter.batchCount = prop.asNumber().toInt(); break; case "onLoadMore": + if (!prop.isString()) { + return; + } this.onLoadMoreFuncId = prop.asString().value(); break; case "loadMoreView": + if (!prop.isString()) { + return; + } this.loadMoreViewId = prop.asString().value(); break; case "loadMore": + if (!prop.isBoolean()) { + return; + } this.loadMore = prop.asBoolean().value(); break; case "onScroll": + if (!prop.isString()) { + return; + } this.onScrollFuncId = prop.asString().value(); break; case "onScrollEnd": + if (!prop.isString()) { + return; + } this.onScrollEndFuncId = prop.asString().value(); break; default: diff --git a/doric-android/doric/src/main/java/pub/doric/shader/list/ListNode.java b/doric-android/doric/src/main/java/pub/doric/shader/list/ListNode.java index 3b26b313..8358e760 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/list/ListNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/list/ListNode.java @@ -136,9 +136,15 @@ public class ListNode extends SuperNode implements IDoricScrollabl protected void blend(RecyclerView view, String name, JSValue prop) { switch (name) { case "itemCount": + if (!prop.isNumber()) { + return; + } this.itemCount = prop.asNumber().toInt(); break; case "renderItem": + if (!prop.isString()) { + return; + } String funcId = prop.asString().value(); if (!funcId.equals(this.renderItemFuncId)) { this.renderItemFuncId = funcId; @@ -162,9 +168,15 @@ public class ListNode extends SuperNode implements IDoricScrollabl this.loadMore = prop.asBoolean().value(); break; case "onScroll": + if (!prop.isString()) { + return; + } this.onScrollFuncId = prop.asString().value(); break; case "onScrollEnd": + if (!prop.isString()) { + return; + } this.onScrollEndFuncId = prop.asString().value(); break; default: