Skip to content

Fix: scrapped views crash #1063

Open
MrRefactor wants to merge 2 commits intomasterfrom
fix/scrapped-views-yolo
Open

Fix: scrapped views crash #1063
MrRefactor wants to merge 2 commits intomasterfrom
fix/scrapped-views-yolo

Conversation

@MrRefactor
Copy link
Collaborator

Summary

Test Plan

What's required for testing (prerequisites)?

What are the steps to reproduce (after prerequisites)?

Compatibility

OS Implemented
iOS
Android

Checklist

  • I have tested this on a device and a simulator
  • I added the documentation in README.md
  • I updated the typed files (TS and Flow)

override fun onBindViewHolder(holder: ViewPagerViewHolder, index: Int) {
val container: FrameLayout = holder.container
val child = getChildAt(index)
holder.setIsRecyclable(false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be reverted, since we don't want to have a recyclable view

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not revert it, thats the reason why we have a crash there - RecyclerView's internal lifecycle assumes holders CAN be recycled. When they can't, they accumulate in limbo — still attached to the layout, but unable to be cleaned up. Eventually RecyclerView tries to force-recycle them during scroll/layout passes and hits the isAttached:true crash. It's a contract violation.

Also the React Native child views are NOT destroyed when a holder is recycled — they're stored in the childrenViews list and survive independently. Only the FrameLayout container is reused. When RecyclerView rebinds a recycled holder to a new position, onBindViewHolder already handles this correctly:

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR targets an Android crash related to ViewPager2/RecyclerView “scrapped” (recycled) views by improving cleanup behavior during view recycling and teardown, and updates example dependency lockfiles to reflect the current package/pod versions.

Changes:

  • Update ViewPagerAdapter to better handle recycling by removing container children on recycle/failure-to-recycle and by detaching views from their parents more safely.
  • Add onDropViewInstance cleanup to stop internal scrolling and detach the underlying RecyclerView adapter when the native view is dropped.
  • Refresh lockfiles (CocoaPods + Bun) in the repo and example app.

Reviewed changes

Copilot reviewed 2 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
example/ios/Podfile.lock Updates resolved pod versions/checksums for the example iOS app.
example/bun.lockb Updates Bun dependency lock for the example app.
bun.lockb Updates Bun dependency lock at the repo root.
android/src/main/java/com/reactnativepagerview/ViewPagerAdapter.kt Adjusts page view attach/detach and adds recycling cleanup hooks.
android/src/main/java/com/reactnativepagerview/PagerViewViewManager.kt Adds teardown cleanup on view drop for the internal RecyclerView/ViewPager2.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@MrRefactor MrRefactor force-pushed the fix/scrapped-views-yolo branch from f951f22 to dff560b Compare March 11, 2026 13:07
@MrRefactor MrRefactor force-pushed the fix/scrapped-views-yolo branch from dff560b to 49106df Compare March 11, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants