feat:Fix List call onLoadMore multi times

This commit is contained in:
pengfeizhou
2021-02-02 19:47:15 +08:00
committed by osborn
parent 438d7233ff
commit 112e45af06
5 changed files with 250 additions and 108 deletions

View File

@@ -45,6 +45,7 @@ class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolder> {
}
private int itemCount = 0;
private int loadAnchor = 0;
@NonNull
@Override
@@ -62,8 +63,8 @@ class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolder> {
holder.listItemNode.setId(jsObject.getProperty("id").asString().value());
holder.listItemNode.blend(jsObject.getProperty("props").asObject());
}
if (position >= this.listNode.itemCount) {
this.listNode.callJSResponse(this.listNode.onLoadMoreFuncId);
if (position >= this.listNode.itemCount && !TextUtils.isEmpty(this.listNode.onLoadMoreFuncId)) {
callLoadMore();
}
}
@@ -142,6 +143,13 @@ class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolder> {
}
}
private void callLoadMore() {
if (loadAnchor != itemCount) {
loadAnchor = itemCount;
this.listNode.callJSResponse(this.listNode.onLoadMoreFuncId);
}
}
static class DoricViewHolder extends RecyclerView.ViewHolder {
ListItemNode listItemNode;

View File

@@ -16,7 +16,6 @@
package pub.doric.shader.list;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
@@ -63,7 +62,6 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
private String onScrollFuncId;
private String onScrollEndFuncId;
private final DoricJSDispatcher jsDispatcher = new DoricJSDispatcher();
public ListNode(DoricContext doricContext) {
super(doricContext);
this.listAdapter = new ListAdapter(this);