render demo
This commit is contained in:
@@ -44,15 +44,16 @@ public abstract class GroupNode<F extends ViewGroup> extends ViewNode<F> {
|
||||
child.ids.addAll(this.ids);
|
||||
child.ids.add(id);
|
||||
mChildrenNode.put(id, child);
|
||||
mView.addView(child.mView, i);
|
||||
} else if (i != child.index) {
|
||||
mIndexInfo.remove(child.index);
|
||||
mIndexInfo.remove(i);
|
||||
child.index = i;
|
||||
mView.removeView(child.mView);
|
||||
mView.addView(child.mView, i);
|
||||
}
|
||||
child.blend(childObj.getProperty("props").asObject());
|
||||
mIndexInfo.put(i, child);
|
||||
if (mIndexInfo.get(i) == null) {
|
||||
mView.addView(child.mView, i);
|
||||
mIndexInfo.put(i, child);
|
||||
}
|
||||
}
|
||||
while (i < mView.getChildCount()) {
|
||||
mView.removeViewAt(mView.getChildCount() - 1);
|
||||
|
@@ -5,6 +5,7 @@ import android.widget.TextView;
|
||||
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.JSValue;
|
||||
|
||||
/**
|
||||
* @Description: widget
|
||||
@@ -21,4 +22,16 @@ public class TextNode extends ViewNode<TextView> {
|
||||
public TextView build(JSObject jsObject) {
|
||||
return new TextView(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void blend(TextView view, String name, JSValue prop) {
|
||||
switch (name) {
|
||||
case "text":
|
||||
view.setText(prop.asString().toString());
|
||||
break;
|
||||
default:
|
||||
super.blend(view, name, prop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ import com.github.penfeizhou.doric.utils.DoricConstant;
|
||||
import com.github.penfeizhou.doric.utils.DoricMetaInfo;
|
||||
import com.github.penfeizhou.doric.utils.DoricUtils;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -39,7 +40,7 @@ public abstract class ViewNode<T extends View> extends DoricComponent {
|
||||
|
||||
public abstract T build(JSObject jsObject);
|
||||
|
||||
public void blend(JSObject jsObject) {
|
||||
void blend(JSObject jsObject) {
|
||||
if (mView == null) {
|
||||
mView = build(jsObject);
|
||||
}
|
||||
@@ -48,7 +49,38 @@ public abstract class ViewNode<T extends View> extends DoricComponent {
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
}
|
||||
setFrame(mView.getLayoutParams(), jsObject);
|
||||
for (String prop : jsObject.propertySet()) {
|
||||
blend(mView, prop, jsObject.getProperty(prop));
|
||||
}
|
||||
mView.setLayoutParams(mView.getLayoutParams());
|
||||
}
|
||||
|
||||
protected void blend(T view, String name, JSValue prop) {
|
||||
switch (name) {
|
||||
case "width":
|
||||
view.getLayoutParams().width = DoricUtils.dp2px(prop.asNumber().toFloat());
|
||||
break;
|
||||
case "height":
|
||||
view.getLayoutParams().height = DoricUtils.dp2px(prop.asNumber().toFloat());
|
||||
break;
|
||||
case "x":
|
||||
if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
|
||||
float x = prop.asNumber().toFloat();
|
||||
((ViewGroup.MarginLayoutParams) mView.getLayoutParams()).leftMargin = DoricUtils.dp2px(x);
|
||||
}
|
||||
break;
|
||||
case "y":
|
||||
if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
|
||||
float y = prop.asNumber().toFloat();
|
||||
((ViewGroup.MarginLayoutParams) mView.getLayoutParams()).topMargin = DoricUtils.dp2px(y);
|
||||
}
|
||||
break;
|
||||
case "bgColor":
|
||||
view.setBackgroundColor(prop.asNumber().toInt());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
|
Reference in New Issue
Block a user