Skip to content

Commit

Permalink
fix(android): setItemPrefetchEnabled to false for recycler view
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 authored and hippy-actions[bot] committed Mar 14, 2024
1 parent 8139a6d commit 658c893
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.openhippy.pool;

import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.util.Pools;
Expand Down Expand Up @@ -51,6 +52,10 @@ public View acquire(@NonNull String key) {

@Override
public void release(@NonNull View instance) {
if (instance.getParent() instanceof ViewGroup) {
ViewGroup parent = (ViewGroup) instance.getParent();
parent.removeView(instance);
}
String className = instance.getClass().getName();
release(className, instance);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.tencent.mtt.hippy.modules.Promise;
import com.tencent.mtt.hippy.views.custom.HippyCustomPropsController;
import com.tencent.mtt.hippy.views.hippylist.HippyRecyclerViewController;
import com.tencent.mtt.hippy.views.hippylist.HippyRecyclerViewWrapper;
import com.tencent.mtt.hippy.views.image.HippyImageViewController;
import com.tencent.mtt.hippy.views.list.HippyListItemViewController;
import com.tencent.mtt.hippy.views.modal.HippyModalHostManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public void onDestroy() {
}
}

protected void deleteChild(View childView) {
removeView(childView);
disableRecycle(childView);
}

public ADP getAdapter() {
return listAdapter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class HippyRecyclerViewController<HRW extends HippyRecyclerViewWrapper> e

@Override
public void onViewDestroy(HRW viewGroup) {
((HRW) viewGroup).getRecyclerView().onDestroy();
((HRW) viewGroup).onDestroy();
}

@Override
Expand All @@ -84,8 +84,7 @@ public View getChildAt(HRW viewGroup, int index) {
*/
@Override
protected void deleteChild(ViewGroup parentView, View childView) {
super.deleteChild(parentView, childView);
((HRW) parentView).getRecyclerView().disableRecycle(childView);
((HRW) parentView).getRecyclerView().deleteChild(childView);
}

@Override
Expand All @@ -101,6 +100,11 @@ public void onBatchComplete(@NonNull HRW view) {
view.setListData();
}

@Override
public boolean isRecyclable() {
return false;
}

@Override
protected View createViewImpl(Context context) {
return createViewImpl(context, null);
Expand All @@ -115,6 +119,7 @@ protected View createViewImpl(@NonNull Context context, @Nullable Map<String, Ob
protected HippyRecyclerView initDefault(@NonNull Context context,
@Nullable Map<String, Object> props, HippyRecyclerView recyclerView) {
LinearLayoutManager layoutManager = new HippyLinearLayoutManager(context);
layoutManager.setItemPrefetchEnabled(false);
recyclerView.setItemAnimator(null);
boolean enableOverPull = true;
boolean hasStableIds = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ public void onBatchComplete() {
recyclerView.onBatchComplete();
}

public void onDestroy() {
recyclerView.onDestroy();
}

@Override
public void setNestedScrollPriority(int direction, Priority priority) {
recyclerView.setNestedScrollPriority(direction, priority);
Expand Down

0 comments on commit 658c893

Please sign in to comment.