Skip to content

Commit e4d0c6b

Browse files
authored
fix(ios): update pager view only when layout changed (#462)
Currently we update the pager view in `layoutSubviews` method to make sure that our layout stays in sync. However, this method seems to get called even if the layout didn't change - and calling `updateDataSource` dismisses the keyboard if it's visible, This causes the keyboard to be dismissed when it's not supposed to - e.g. auto focus on input doesn't work, keyboard doesn't stay open when app goes to background etc. This adds a check to make sure that we call `updateDataSourcez only if the layout changes, which avoids unnecessary updates and avoids dismissing the keyboard unnecessarily. Fixes #441
1 parent c0e8d20 commit e4d0c6b

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

ios/ReactNativePageView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
2323
@property(nonatomic, copy) RCTDirectEventBlock onPageScrollStateChanged;
2424
@property(nonatomic) BOOL overdrag;
2525
@property(nonatomic) NSString* layoutDirection;
26+
@property(nonatomic) CGRect previousBounds;
2627

2728

2829
- (void)goTo:(NSInteger)index animated:(BOOL)animated;

ios/ReactNativePageView.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher {
4747
_cachedControllers = [NSHashTable weakObjectsHashTable];
4848
_overdrag = NO;
4949
_layoutDirection = @"ltr";
50+
_previousBounds = CGRectMake(0, 0, 0, 0);
5051
}
5152
return self;
5253
}
@@ -55,8 +56,13 @@ - (void)layoutSubviews {
5556
[super layoutSubviews];
5657
if (self.reactPageViewController) {
5758
[self shouldScroll:self.scrollEnabled];
58-
//Below line fix bug, where the view does not update after orientation changed.
59-
[self updateDataSource];
59+
60+
if (!CGRectEqualToRect(self.previousBounds, CGRectMake(0, 0, 0, 0)) && !CGRectEqualToRect(self.bounds, self.previousBounds)) {
61+
// Below line fix bug, where the view does not update after orientation changed.
62+
[self updateDataSource];
63+
}
64+
65+
self.previousBounds = CGRectMake(self.bounds.origin.x, self.bounds.origin.y, self.bounds.size.width, self.bounds.size.height);
6066
}
6167
}
6268

0 commit comments

Comments
 (0)