Conversation
| override fun onBindViewHolder(holder: ViewPagerViewHolder, index: Int) { | ||
| val container: FrameLayout = holder.container | ||
| val child = getChildAt(index) | ||
| holder.setIsRecyclable(false) |
There was a problem hiding this comment.
I think it should be reverted, since we don't want to have a recyclable view
There was a problem hiding this comment.
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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
ViewPagerAdapterto better handle recycling by removing container children on recycle/failure-to-recycle and by detaching views from their parents more safely. - Add
onDropViewInstancecleanup 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.
android/src/main/java/com/reactnativepagerview/PagerViewViewManager.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/reactnativepagerview/ViewPagerAdapter.kt
Outdated
Show resolved
Hide resolved
f951f22 to
dff560b
Compare
dff560b to
49106df
Compare
Summary
Test Plan
What's required for testing (prerequisites)?
What are the steps to reproduce (after prerequisites)?
Compatibility
Checklist
README.md