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 66f79f46..3a478c7a 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 @@ -88,6 +88,7 @@ public class FlowLayoutNode extends SuperNode implements IDoricScr private String onScrollFuncId; private String onScrollEndFuncId; private DoricJSDispatcher jsDispatcher = new DoricJSDispatcher(); + private int itemCount = 0; public FlowLayoutNode(DoricContext doricContext) { super(doricContext); @@ -138,7 +139,7 @@ public class FlowLayoutNode extends SuperNode implements IDoricScr if (!prop.isNumber()) { return; } - this.flowAdapter.itemCount = prop.asNumber().toInt(); + this.itemCount = prop.asNumber().toInt(); break; case "renderItem": if (!prop.isString()) { @@ -220,6 +221,7 @@ public class FlowLayoutNode extends SuperNode implements IDoricScr mView.post(new Runnable() { @Override public void run() { + flowAdapter.itemCount = itemCount; flowAdapter.notifyDataSetChanged(); } }); diff --git a/doric-android/doric/src/main/java/pub/doric/shader/list/ListAdapter.java b/doric-android/doric/src/main/java/pub/doric/shader/list/ListAdapter.java index ea645280..7ae3d928 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/list/ListAdapter.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/list/ListAdapter.java @@ -44,6 +44,8 @@ class ListAdapter extends RecyclerView.Adapter { this.listNode = listNode; } + private int itemCount = 0; + @NonNull @Override public DoricViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { @@ -67,7 +69,7 @@ class ListAdapter extends RecyclerView.Adapter { @Override public int getItemCount() { - return this.listNode.itemCount + (this.listNode.loadMore ? 1 : 0); + return this.itemCount; } @Override @@ -84,6 +86,10 @@ class ListAdapter extends RecyclerView.Adapter { return super.getItemViewType(position); } + public void setItemCount(int itemCount) { + this.itemCount = itemCount; + } + private JSValue getItemModel(int position) { if (position >= this.listNode.itemCount) { return this.listNode.getSubModel(this.listNode.loadMoreViewId); 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 1a3fce41..feed3955 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 @@ -59,10 +59,10 @@ public class ListNode extends SuperNode implements IDoricScrollabl SparseArray itemValues = new SparseArray<>(); boolean loadMore = false; String loadMoreViewId; - private Set listeners = new HashSet<>(); + private final Set listeners = new HashSet<>(); private String onScrollFuncId; private String onScrollEndFuncId; - private DoricJSDispatcher jsDispatcher = new DoricJSDispatcher(); + private final DoricJSDispatcher jsDispatcher = new DoricJSDispatcher(); public ListNode(DoricContext doricContext) { super(doricContext); @@ -137,6 +137,7 @@ public class ListNode extends SuperNode implements IDoricScrollabl mView.post(new Runnable() { @Override public void run() { + listAdapter.setItemCount(itemCount + (loadMore ? 1 : 0)); listAdapter.notifyDataSetChanged(); } }); diff --git a/doric-android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java b/doric-android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java index 451d3311..e467fa2b 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java @@ -44,6 +44,7 @@ public class SliderNode extends SuperNode { private final SlideAdapter slideAdapter; private String onPageSlidedFuncId; private int lastPosition = 0; + private int itemCount = 0; public SliderNode(DoricContext doricContext) { super(doricContext); @@ -135,6 +136,7 @@ public class SliderNode extends SuperNode { mView.post(new Runnable() { @Override public void run() { + slideAdapter.itemCount = itemCount; slideAdapter.notifyDataSetChanged(); } }); @@ -145,7 +147,7 @@ public class SliderNode extends SuperNode { protected void blend(RecyclerView view, String name, JSValue prop) { switch (name) { case "itemCount": - this.slideAdapter.itemCount = prop.asNumber().toInt(); + this.itemCount = prop.asNumber().toInt(); break; case "renderPage": // If reset renderItem,should reset native cache.