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 {