From be2767c296c695aa604e676e0e2d0d0a92207200 Mon Sep 17 00:00:00 2001 From: liuxiaoyan5 Date: Fri, 7 Apr 2023 20:22:11 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[MOD]=20=E4=BF=AE=E6=94=B9List=EF=BC=8C?= =?UTF-8?q?=E9=BB=98=E8=AE=A4type=20=3D=200=20=E8=AE=BE=E7=BD=AE=20?= =?UTF-8?q?=E6=9C=80=E5=A4=A7=E7=BC=93=E5=86=B2=E6=B1=A0=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E4=B8=BA20=20=E6=89=A9=E5=B1=95=EF=BC=8C=E6=96=B0=E5=A2=9EAPI?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E5=89=8D=E7=AB=AF=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=8C=87=E5=AE=9Atype=E7=9A=84=E7=BC=93=E5=86=B2=E6=B1=A0?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/didi/hummer/component/list/List.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/android/hummer-component/src/main/java/com/didi/hummer/component/list/List.java b/android/hummer-component/src/main/java/com/didi/hummer/component/list/List.java index 7fa8c2c8..079c3f61 100644 --- a/android/hummer-component/src/main/java/com/didi/hummer/component/list/List.java +++ b/android/hummer-component/src/main/java/com/didi/hummer/component/list/List.java @@ -52,6 +52,8 @@ */ @Component("List") public class List extends HMBase { + private final static int DEFAULT_MAX_RECYCLE_SIZE = 20; + private static final int MODE_LIST = 1; private static final int MODE_GRID = 2; private static final int MODE_WATERFALL = 3; @@ -171,6 +173,9 @@ 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); + //设置默认type的pool大小 + recyclerView.getRecycledViewPool().setMaxRecycledViews(0, DEFAULT_MAX_RECYCLE_SIZE); + recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER); recyclerView.setClipChildren(false); recyclerView.setOnTouchListener((v, event) -> { @@ -670,6 +675,16 @@ public void dbg_getDescription(JSCallback callback, int depth) { super.dbg_getDescription(callback, depth); } + @JsMethod("setMaxRecycledByType") + public void setMaxRecycledByType(int type, int size){ + recyclerView.getRecycledViewPool().setMaxRecycledViews(type, size); + } + + @JsMethod("setMaxRecycled") + public void setMaxRecycled(int size){ + recyclerView.getRecycledViewPool().setMaxRecycledViews(0, size); + } + private void refreshNodeTree() { if (!DebugUtil.isDebuggable(getHummerContext().getNamespace())) { return; From 536d0910ee2e4eb5637ad6849d0d1f22a4e23f8b Mon Sep 17 00:00:00 2001 From: liuxiaoyan5 Date: Thu, 13 Apr 2023 10:46:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[MOD]=20=E4=BF=AE=E6=94=B9List=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=80=BB=E8=BE=91=EF=BC=8C=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=AE=BE=E7=BD=AEviewType=E7=9A=84=E5=9B=9E=E6=94=B6=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E6=B1=A0=E5=A4=A7=E5=B0=8F=EF=BC=88100=EF=BC=89?= =?UTF-8?q?=EF=BC=8C=E4=BF=9D=E6=8C=81=E4=B8=8Eios=E7=AB=AF=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=AF=B9=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hummer/component/list/HMListAdapter.java | 20 +++++++++---- .../com/didi/hummer/component/list/List.java | 30 +++++++++++-------- .../list/RecycleViewPoolCallback.java | 5 ++++ 3 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 android/hummer-component/src/main/java/com/didi/hummer/component/list/RecycleViewPoolCallback.java 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 DEFAULT_MAX_RECYCLE_SIZE = 20; + private final static int MAX_RECYCLE_POOL_SIZE = 100; private static final int MODE_LIST = 1; private static final int MODE_GRID = 2; @@ -94,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) { @@ -173,8 +188,6 @@ 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); - //设置默认type的pool大小 - recyclerView.getRecycledViewPool().setMaxRecycledViews(0, DEFAULT_MAX_RECYCLE_SIZE); recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER); recyclerView.setClipChildren(false); @@ -248,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(); @@ -675,16 +689,6 @@ public void dbg_getDescription(JSCallback callback, int depth) { super.dbg_getDescription(callback, depth); } - @JsMethod("setMaxRecycledByType") - public void setMaxRecycledByType(int type, int size){ - recyclerView.getRecycledViewPool().setMaxRecycledViews(type, size); - } - - @JsMethod("setMaxRecycled") - public void setMaxRecycled(int size){ - recyclerView.getRecycledViewPool().setMaxRecycledViews(0, size); - } - private void refreshNodeTree() { if (!DebugUtil.isDebuggable(getHummerContext().getNamespace())) { return; 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); +}