diff --git a/android/hummer-component/src/main/java/com/didi/hummer/component/list/HMListAdapter.java b/android/hummer-component/src/main/java/com/didi/hummer/component/list/HMListAdapter.java index a703efbe..2a5204e6 100644 --- a/android/hummer-component/src/main/java/com/didi/hummer/component/list/HMListAdapter.java +++ b/android/hummer-component/src/main/java/com/didi/hummer/component/list/HMListAdapter.java @@ -20,6 +20,7 @@ public class HMListAdapter extends RecyclerView.Adapter { + private final static int MAX_RECYCLE_POOL_SIZE = 100; + private static final int MODE_LIST = 1; private static final int MODE_GRID = 2; private static final int MODE_WATERFALL = 3; @@ -92,6 +95,20 @@ public class List extends HMBase { private int scrollOffsetX = 0; private int scrollOffsetY = 0; + private HashSet registeredViewType; + private RecycleViewPoolCallback recycleViewPoolCallback = new RecycleViewPoolCallback() { + @Override + public void updatePoolSize(int viewType) { + if(registeredViewType == null){ + registeredViewType = new HashSet<>(); + } + if(!registeredViewType.contains(viewType)){ + recyclerView.getRecycledViewPool().setMaxRecycledViews(viewType, MAX_RECYCLE_POOL_SIZE); + registeredViewType.add(viewType); + } + } + }; + private RecyclerView.OnScrollListener mOnScrollListener = new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { @@ -171,6 +188,7 @@ public List(HummerContext context, JSValue jsValue, String viewID) { protected SmartRefreshLayout createViewInstance(Context context) { // 这里不用代码new一个RecyclerView,而是通过xml,是为了解决设置scrollerbar显示无效的问题 recyclerView = (RecyclerView) LayoutInflater.from(context).inflate(R.layout.recycler_view, null, false); + recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER); recyclerView.setClipChildren(false); recyclerView.setOnTouchListener((v, event) -> { @@ -243,6 +261,7 @@ public void onCreate() { super.onCreate(); recyclerView.addOnScrollListener(mOnScrollListener); adapter = new HMListAdapter(getContext(), instanceManager); + adapter.setRecycleViewPoolCallback(recycleViewPoolCallback); recyclerView.setAdapter(adapter); recyclerViewNode = YogaNodeUtil.createYogaNode(); diff --git a/android/hummer-component/src/main/java/com/didi/hummer/component/list/RecycleViewPoolCallback.java b/android/hummer-component/src/main/java/com/didi/hummer/component/list/RecycleViewPoolCallback.java new file mode 100644 index 00000000..a79faf2c --- /dev/null +++ b/android/hummer-component/src/main/java/com/didi/hummer/component/list/RecycleViewPoolCallback.java @@ -0,0 +1,5 @@ +package com.didi.hummer.component.list; + +interface RecycleViewPoolCallback { + void updatePoolSize(int viewType); +}