diff --git a/Android/app/src/main/java/pub/doric/demo/MainActivity.java b/Android/app/src/main/java/pub/doric/demo/MainActivity.java index a1fcbf5a..22de4f94 100644 --- a/Android/app/src/main/java/pub/doric/demo/MainActivity.java +++ b/Android/app/src/main/java/pub/doric/demo/MainActivity.java @@ -50,7 +50,7 @@ public class MainActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - doricContext = DoricContext.create(this, DoricUtils.readAssetFile("demo/Snake.js"), "test"); + doricContext = DoricContext.create(this, DoricUtils.readAssetFile("demo/ListDemo.js"), "test"); doricContext.init(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); doricContext.getRootNode().setRootView((FrameLayout) findViewById(R.id.root)); diff --git a/Android/doric/src/main/java/pub/doric/shader/GroupNode.java b/Android/doric/src/main/java/pub/doric/shader/GroupNode.java index 37ba92bf..0eaef50c 100644 --- a/Android/doric/src/main/java/pub/doric/shader/GroupNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/GroupNode.java @@ -95,7 +95,7 @@ public abstract class GroupNode extends SuperNode { newNode.init(this); newNode.blend(model.getProperty("props").asObject()); - mChildNodes.set(idx, newNode); + mChildNodes.add(idx, newNode); mView.addView(newNode.getDoricLayer(), idx, newNode.getLayoutParams()); } } diff --git a/Android/doric/src/main/java/pub/doric/shader/SuperNode.java b/Android/doric/src/main/java/pub/doric/shader/SuperNode.java index 672bfe01..76854f18 100644 --- a/Android/doric/src/main/java/pub/doric/shader/SuperNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/SuperNode.java @@ -74,6 +74,10 @@ public abstract class SuperNode extends ViewNode { return subNodes.get(id); } + public void setSubModel(String id, JSObject model) { + subNodes.put(id, model); + } + protected abstract void blendSubNode(JSObject subProperties); protected void blendSubLayoutConfig(ViewNode viewNode, JSObject jsObject) { @@ -127,34 +131,14 @@ public abstract class SuperNode extends ViewNode { } private void mixin(JSObject src, JSObject target) { - JSValue srcProps = src.getProperty("props"); - JSValue targetProps = target.getProperty("props"); - if (srcProps.isObject()) { - if (targetProps.isObject()) { - for (String key : srcProps.asObject().propertySet()) { - JSValue jsValue = srcProps.asObject().getProperty(key); - if ("children".equals(key) && jsValue.isArray()) { - JSValue targetChildren = targetProps.asObject().getProperty("children"); - if (targetChildren.isArray() && targetChildren.asArray().size() == jsValue.asArray().size()) { - for (int i = 0; i < jsValue.asArray().size(); i++) { - JSValue childSrc = jsValue.asArray().get(i); - JSValue childTarget = targetChildren.asArray().get(i); - if (childSrc.isObject()) { - if (childTarget.isObject()) { - mixin(childSrc.asObject(), childTarget.asObject()); - } else { - targetChildren.asArray().put(i, childSrc); - } - } - } - } - continue; - } - targetProps.asObject().setProperty(key, jsValue); - } - } else { - target.setProperty("props", srcProps); + JSObject srcProps = src.getProperty("props").asObject(); + JSObject targetProps = target.getProperty("props").asObject(); + for (String key : srcProps.propertySet()) { + JSValue jsValue = srcProps.getProperty(key); + if ("subviews".equals(key) && jsValue.isArray()) { + continue; } + targetProps.asObject().setProperty(key, jsValue); } } diff --git a/Android/doric/src/main/java/pub/doric/shader/ViewNode.java b/Android/doric/src/main/java/pub/doric/shader/ViewNode.java index 85819503..bbf71432 100644 --- a/Android/doric/src/main/java/pub/doric/shader/ViewNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/ViewNode.java @@ -55,6 +55,7 @@ public abstract class ViewNode extends DoricContextHolder { this.mSuperNode = superNode; this.mLayoutParams = superNode.generateDefaultLayoutParams(); this.doricLayer = new DoricLayer(getContext()); + this.doricLayer.setLayoutParams(mLayoutParams); this.mView = build(); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(mLayoutParams.width, mLayoutParams.height); doricLayer.addView(mView, params); diff --git a/Android/doric/src/main/java/pub/doric/shader/list/ListAdapter.java b/Android/doric/src/main/java/pub/doric/shader/list/ListAdapter.java index 1b9f8764..30dcddf4 100644 --- a/Android/doric/src/main/java/pub/doric/shader/list/ListAdapter.java +++ b/Android/doric/src/main/java/pub/doric/shader/list/ListAdapter.java @@ -15,6 +15,7 @@ */ package pub.doric.shader.list; +import android.text.TextUtils; import android.util.SparseArray; import android.view.View; import android.view.ViewGroup; @@ -24,6 +25,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.github.pengfeizhou.jscore.JSArray; import com.github.pengfeizhou.jscore.JSDecoder; +import com.github.pengfeizhou.jscore.JSNull; import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSValue; @@ -37,12 +39,11 @@ import pub.doric.shader.ViewNode; */ public class ListAdapter extends RecyclerView.Adapter { - final ListNode listNode; + private final ListNode listNode; String renderItemFuncId; - final String renderBunchedItemsFuncId = "renderBunchedItems"; int itemCount = 0; int batchCount = 15; - SparseArray itemValues = new SparseArray<>(); + SparseArray itemValues = new SparseArray<>(); public ListAdapter(ListNode listNode) { this.listNode = listNode; @@ -82,11 +83,11 @@ public class ListAdapter extends RecyclerView.Adapter asyncResult = listNode.callJSResponse( - renderBunchedItemsFuncId, + "renderBunchedItems", position, batchCount); try { @@ -95,20 +96,34 @@ public class ListAdapter extends RecyclerView.Adapter { case "batchCount": this.listAdapter.batchCount = 15; break; + case "subviews": + break; default: super.blend(view, name, prop); break; diff --git a/js-framework/src/ui/listview.ts b/js-framework/src/ui/listview.ts index 60205146..984a5458 100644 --- a/js-framework/src/ui/listview.ts +++ b/js-framework/src/ui/listview.ts @@ -70,7 +70,7 @@ export class List extends Superview implements IList { private renderBunchedItems(start: number, length: number) { return new Array(Math.min(length, this.itemCount - start)).fill(0).map((_, idx) => { const listItem = this.getItem(start + idx) - return listItem.viewId + return listItem.toModel() }) } } \ No newline at end of file