From ea6823f19ee2fe148554582ea7d40f98705301b7 Mon Sep 17 00:00:00 2001 From: MrRefactor Date: Sat, 16 Nov 2024 06:56:46 +0100 Subject: [PATCH] fix(android) Fix crash with navigation on fabric by proper removal of view --- .../PagerViewViewManagerImpl.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/reactnativepagerview/PagerViewViewManagerImpl.kt b/android/src/main/java/com/reactnativepagerview/PagerViewViewManagerImpl.kt index 0abf6682..ae6ef586 100644 --- a/android/src/main/java/com/reactnativepagerview/PagerViewViewManagerImpl.kt +++ b/android/src/main/java/com/reactnativepagerview/PagerViewViewManagerImpl.kt @@ -69,12 +69,19 @@ object PagerViewViewManagerImpl { fun removeViewAt(parent: NestedScrollableHost, index: Int) { val pager = getViewPager(parent) val adapter = pager.adapter as ViewPagerAdapter? + + val child = adapter?.getChildAt(index) + + if (child != null && child.parent != null) { + (child.parent as? ViewGroup)?.removeView(child) + } + adapter?.removeChildAt(index) - // Required so ViewPager actually animates the removed view right away (otherwise - // a white screen is shown until the next user interaction). - // https://github.com/facebook/react-native/issues/17968#issuecomment-697136929 - refreshViewChildrenLayout(pager) + pager.post { + pager.invalidate() + pager.requestLayout() + } } fun needsCustomLayoutForChildren(): Boolean {