diff --git a/doric/src/main/java/pub/doric/shader/flowlayout/FlowAdapter.java b/doric/src/main/java/pub/doric/shader/flowlayout/FlowAdapter.java index 00c2f9fa..ea9001e0 100644 --- a/doric/src/main/java/pub/doric/shader/flowlayout/FlowAdapter.java +++ b/doric/src/main/java/pub/doric/shader/flowlayout/FlowAdapter.java @@ -22,6 +22,7 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; +import androidx.recyclerview.widget.StaggeredGridLayoutManager; import com.github.pengfeizhou.jscore.JSArray; import com.github.pengfeizhou.jscore.JSDecoder; @@ -65,15 +66,28 @@ class FlowAdapter extends RecyclerView.Adapter { holder.flowLayoutItemNode.setId(jsObject.getProperty("id").asString().value()); holder.flowLayoutItemNode.blend(jsObject.getProperty("props").asObject()); } + if (position >= this.itemCount) { + this.flowLayoutNode.callJSResponse(this.flowLayoutNode.onLoadMoreFuncId); + + StaggeredGridLayoutManager.LayoutParams layoutParams = new StaggeredGridLayoutManager.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + holder.itemView.getLayoutParams().height + ); + layoutParams.setFullSpan(true); + holder.itemView.setLayoutParams(layoutParams); + } } @Override public int getItemCount() { - return itemCount; + return this.itemCount + (this.flowLayoutNode.loadMore ? 1 : 0); } @Override public int getItemViewType(int position) { + if (position >= itemCount) { + return Integer.MAX_VALUE; + } JSValue value = getItemModel(position); if (value.isObject()) { if (value.asObject().getProperty("identifier").isString()) { @@ -84,6 +98,9 @@ class FlowAdapter extends RecyclerView.Adapter { } private JSValue getItemModel(final int position) { + if (position >= this.itemCount) { + return this.flowLayoutNode.getSubModel(this.flowLayoutNode.loadMoreViewId); + } String id = itemValues.get(position); if (TextUtils.isEmpty(id)) { AsyncResult asyncResult = flowLayoutNode.callJSResponse( diff --git a/doric/src/main/java/pub/doric/shader/flowlayout/FlowLayoutNode.java b/doric/src/main/java/pub/doric/shader/flowlayout/FlowLayoutNode.java index 14e7b94c..c01c543c 100644 --- a/doric/src/main/java/pub/doric/shader/flowlayout/FlowLayoutNode.java +++ b/doric/src/main/java/pub/doric/shader/flowlayout/FlowLayoutNode.java @@ -70,6 +70,9 @@ public class FlowLayoutNode extends SuperNode { outRect.set(columnSpace / 2, rowSpace / 2, columnSpace / 2, rowSpace / 2); } }; + String onLoadMoreFuncId; + boolean loadMore = false; + String loadMoreViewId; public FlowLayoutNode(DoricContext doricContext) { super(doricContext); @@ -115,13 +118,24 @@ public class FlowLayoutNode extends SuperNode { if (!funcId.equals(this.flowAdapter.renderItemFuncId)) { this.flowAdapter.renderItemFuncId = funcId; // If reset renderItem,should reset native cache. + for (int index = 0; index < this.flowAdapter.itemValues.size(); index++) { + removeSubModel(this.flowAdapter.itemValues.valueAt(index)); + } this.flowAdapter.itemValues.clear(); - clearSubModel(); } break; case "batchCount": this.flowAdapter.batchCount = prop.asNumber().toInt(); break; + case "onLoadMore": + this.onLoadMoreFuncId = prop.asString().value(); + break; + case "loadMoreView": + this.loadMoreViewId = prop.asString().value(); + break; + case "loadMore": + this.loadMore = prop.asBoolean().value(); + break; default: super.blend(view, name, prop); break;