Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): setItemPrefetchEnabled to false for recycler view #3778

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading