android:add data type check for blending
This commit is contained in:
parent
75fbb3d527
commit
66afc4c4bb
@ -40,10 +40,19 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> 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
|
||||
|
@ -188,6 +188,9 @@ public class ImageNode extends ViewNode<ImageView> {
|
||||
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<ImageView> {
|
||||
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<ImageView> {
|
||||
}
|
||||
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",
|
||||
|
@ -62,6 +62,9 @@ public class LinearNode extends GroupNode<LinearLayout> {
|
||||
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<LinearLayout> {
|
||||
view.setDividerDrawable(shapeDrawable);
|
||||
break;
|
||||
case "gravity":
|
||||
if (!prop.isNumber()) {
|
||||
return;
|
||||
}
|
||||
view.setGravity(prop.asNumber().toInt());
|
||||
break;
|
||||
default:
|
||||
|
@ -99,10 +99,19 @@ public class ScrollerNode extends SuperNode<HVScrollView> 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);
|
||||
|
@ -52,9 +52,15 @@ public class SwitchNode extends ViewNode<SwitchCompat> {
|
||||
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<SwitchCompat> {
|
||||
});
|
||||
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:
|
||||
|
@ -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<TextView> {
|
||||
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<TextView> {
|
||||
}
|
||||
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<TextView> {
|
||||
|
||||
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:
|
||||
|
@ -148,6 +148,9 @@ public abstract class ViewNode<T extends View> 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<T extends View> extends DoricContextHolder {
|
||||
}
|
||||
break;
|
||||
case "height":
|
||||
if (!prop.isNumber()) {
|
||||
return;
|
||||
}
|
||||
if (isAnimating()) {
|
||||
addAnimator(ObjectAnimator.ofFloat(
|
||||
this,
|
||||
@ -170,6 +176,9 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
}
|
||||
break;
|
||||
case "x":
|
||||
if (!prop.isNumber()) {
|
||||
return;
|
||||
}
|
||||
if (isAnimating()) {
|
||||
addAnimator(ObjectAnimator.ofFloat(
|
||||
this,
|
||||
@ -181,6 +190,9 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
}
|
||||
break;
|
||||
case "y":
|
||||
if (!prop.isNumber()) {
|
||||
return;
|
||||
}
|
||||
if (isAnimating()) {
|
||||
addAnimator(ObjectAnimator.ofFloat(
|
||||
this,
|
||||
@ -248,6 +260,9 @@ public abstract class ViewNode<T extends View> 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<T extends View> extends DoricContextHolder {
|
||||
}
|
||||
break;
|
||||
case "alpha":
|
||||
if (!prop.isNumber()) {
|
||||
return;
|
||||
}
|
||||
if (isAnimating()) {
|
||||
addAnimator(ObjectAnimator.ofFloat(
|
||||
this,
|
||||
@ -310,6 +328,9 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
}
|
||||
break;
|
||||
case "translationX":
|
||||
if (!prop.isNumber()) {
|
||||
return;
|
||||
}
|
||||
if (isAnimating()) {
|
||||
addAnimator(ObjectAnimator.ofFloat(
|
||||
this,
|
||||
@ -321,6 +342,9 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
}
|
||||
break;
|
||||
case "translationY":
|
||||
if (!prop.isNumber()) {
|
||||
return;
|
||||
}
|
||||
if (isAnimating()) {
|
||||
addAnimator(ObjectAnimator.ofFloat(
|
||||
this,
|
||||
@ -332,6 +356,9 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
}
|
||||
break;
|
||||
case "scaleX":
|
||||
if (!prop.isNumber()) {
|
||||
return;
|
||||
}
|
||||
if (isAnimating()) {
|
||||
addAnimator(ObjectAnimator.ofFloat(
|
||||
this,
|
||||
@ -343,6 +370,9 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
}
|
||||
break;
|
||||
case "scaleY":
|
||||
if (!prop.isNumber()) {
|
||||
return;
|
||||
}
|
||||
if (isAnimating()) {
|
||||
addAnimator(ObjectAnimator.ofFloat(
|
||||
this,
|
||||
@ -354,6 +384,9 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
}
|
||||
break;
|
||||
case "pivotX":
|
||||
if (!prop.isNumber()) {
|
||||
return;
|
||||
}
|
||||
if (isAnimating()) {
|
||||
addAnimator(ObjectAnimator.ofFloat(
|
||||
this,
|
||||
@ -365,6 +398,9 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
}
|
||||
break;
|
||||
case "pivotY":
|
||||
if (!prop.isNumber()) {
|
||||
return;
|
||||
}
|
||||
if (isAnimating()) {
|
||||
addAnimator(ObjectAnimator.ofFloat(
|
||||
this,
|
||||
@ -376,6 +412,9 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
}
|
||||
break;
|
||||
case "rotation":
|
||||
if (!prop.isNumber()) {
|
||||
return;
|
||||
}
|
||||
if (isAnimating()) {
|
||||
addAnimator(ObjectAnimator.ofFloat(
|
||||
this,
|
||||
|
@ -113,18 +113,33 @@ public class FlowLayoutNode extends SuperNode<RecyclerView> 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<RecyclerView> 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:
|
||||
|
@ -136,9 +136,15 @@ public class ListNode extends SuperNode<RecyclerView> 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<RecyclerView> 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:
|
||||
|
Reference in New Issue
Block a user