Skip to content

Commit 9eb7b34

Browse files
authored
fix(android): handling initially empty pages (#408)
1 parent 4bd67ca commit 9eb7b34

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ class PagerViewViewManager : ViewGroupManager<ViewPager2>() {
101101
return
102102
}
103103
(parent.adapter as FragmentAdapter?)?.addFragment(child, index)
104+
105+
if (parent.currentItem == index) {
106+
// Solves https://github.com/callstack/react-native-pager-view/issues/219
107+
// Required so ViewPager actually displays first dynamically added child
108+
// (otherwise a white screen is shown until the next user interaction).
109+
// https://github.com/facebook/react-native/issues/17968#issuecomment-697136929
110+
refreshViewChildrenLayout(parent)
111+
}
104112
}
105113

106114
override fun getChildCount(parent: ViewPager2): Int {

ios/ReactNativePageView.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ - (UIViewController *)findCachedControllerForView:(UIView *)view {
198198
}
199199

200200
- (void)updateDataSource {
201-
if (!self.currentView) {
201+
if (!self.currentView && self.reactSubviews.count == 0) {
202202
return;
203203
}
204204

205-
NSInteger newIndex = [self.reactSubviews indexOfObject:self.currentView];
205+
NSInteger newIndex = self.currentView ? [self.reactSubviews indexOfObject:self.currentView] : 0;
206206

207207
if (newIndex == NSNotFound) {
208208
// Current view was removed

0 commit comments

Comments
 (0)