Skip to content

Commit 9ea6b49

Browse files
committed
wip
1 parent 2c4ea72 commit 9ea6b49

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

android/src/main/java/com/reactnativepagerview/PagerViewViewManager.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,17 @@ class PagerViewViewManager : ViewGroupManager<NestedScrollableHost>(), RNCViewPa
9595
}
9696

9797
override fun onDropViewInstance(view: NestedScrollableHost) {
98-
stopScrollIfNeeded(view)
99-
val recyclerView = (view.getChildAt(0) as? ViewPager2)?.getChildAt(0) as? RecyclerView
100-
recyclerView?.swapAdapter(null, false)
98+
val vp = view.getChildAt(0) as? ViewPager2
99+
val recyclerView = vp?.getChildAt(0) as? RecyclerView
100+
recyclerView?.stopScroll()
101+
try {
102+
// Clear adapter to prevent post-teardown fling callbacks.
103+
// setAdapter(null) internally calls removeAndRecycleAllViews which
104+
// can throw if views are still attached during mid-scroll teardown.
105+
recyclerView?.adapter = null
106+
} catch (_: IllegalArgumentException) {
107+
// Safe to ignore during teardown — view is being destroyed
108+
}
101109
super.onDropViewInstance(view)
102110
}
103111

0 commit comments

Comments
 (0)