Skip to content

Commit 457eeb1

Browse files
authored
fix(ios): fix freeze after calling setpage (#654)
1 parent 78b51e3 commit 457eeb1

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

example/ios/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ PODS:
302302
- React-jsinspector (0.70.5)
303303
- React-logger (0.70.5):
304304
- glog
305-
- react-native-pager-view (6.1.0):
305+
- react-native-pager-view (6.1.1):
306306
- React-Core
307307
- react-native-safe-area-context (3.4.1):
308308
- React-Core
@@ -617,7 +617,7 @@ SPEC CHECKSUMS:
617617
React-jsiexecutor: 31564fa6912459921568e8b0e49024285a4d584b
618618
React-jsinspector: badd81696361249893a80477983e697aab3c1a34
619619
React-logger: fdda34dd285bdb0232e059b19d9606fa0ec3bb9c
620-
react-native-pager-view: 7abf89f9834d9a4021b2fb6a5ef2abff570b46fb
620+
react-native-pager-view: 3c66c4e2f3ab423643d07b2c7041f8ac48395f72
621621
react-native-safe-area-context: 9e40fb181dac02619414ba1294d6c2a807056ab9
622622
React-perflogger: e68d3795cf5d247a0379735cbac7309adf2fb931
623623
React-RCTActionSheet: 05452c3b281edb27850253db13ecd4c5a65bc247
@@ -640,6 +640,6 @@ SPEC CHECKSUMS:
640640
Yoga: eca980a5771bf114c41a754098cd85e6e0d90ed7
641641
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
642642

643-
PODFILE CHECKSUM: 19416d7ab85e40fb19965457402ab8bdea762543
643+
PODFILE CHECKSUM: 7bb6ac2c486fd5b7d13ac3d8fc31d2174d38be56
644644

645645
COCOAPODS: 1.11.3

fabricexample/ios/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ PODS:
625625
- React-jsinspector (0.70.5)
626626
- React-logger (0.70.5):
627627
- glog
628-
- react-native-pager-view (6.1.0):
628+
- react-native-pager-view (6.1.1):
629629
- RCT-Folly
630630
- RCTRequired
631631
- RCTTypeSafety
@@ -1013,7 +1013,7 @@ SPEC CHECKSUMS:
10131013
React-jsiexecutor: 31564fa6912459921568e8b0e49024285a4d584b
10141014
React-jsinspector: badd81696361249893a80477983e697aab3c1a34
10151015
React-logger: fdda34dd285bdb0232e059b19d9606fa0ec3bb9c
1016-
react-native-pager-view: dc682417cd0b172774331c3f664c23987b4c2eed
1016+
react-native-pager-view: 22ef94ca5a46cb18e4573ed3e179f4f84d477490
10171017
react-native-safe-area-context: 2f75b317784a1a8e224562941e50ecbc932d2097
10181018
React-perflogger: e68d3795cf5d247a0379735cbac7309adf2fb931
10191019
React-RCTActionSheet: 05452c3b281edb27850253db13ecd4c5a65bc247
@@ -1037,6 +1037,6 @@ SPEC CHECKSUMS:
10371037
Yoga: eca980a5771bf114c41a754098cd85e6e0d90ed7
10381038
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
10391039

1040-
PODFILE CHECKSUM: 5bfcc361dd0b2672ce6c798a07debb9513901bf6
1040+
PODFILE CHECKSUM: 543e2b50cb719b002eca725e63b881ca716979e9
10411041

10421042
COCOAPODS: 1.11.3

ios/Fabric/RNCPagerViewComponentView.mm

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,18 @@ - (void)setPageWithoutAnimation:(NSInteger)index {
173173
[self goTo:index animated:NO];
174174
}
175175

176+
- (void)disableSwipe {
177+
self.nativePageViewController.view.userInteractionEnabled = NO;
178+
}
179+
180+
- (void)enableSwipe {
181+
self.nativePageViewController.view.userInteractionEnabled = YES;
182+
}
183+
176184
- (void)goTo:(NSInteger)index animated:(BOOL)animated {
177185
NSInteger numberOfPages = _nativeChildrenViewControllers.count;
178186

179-
_nativePageViewController.view.userInteractionEnabled = NO;
187+
[self disableSwipe];
180188

181189
_destinationIndex = index;
182190

@@ -188,16 +196,19 @@ - (void)goTo:(NSInteger)index animated:(BOOL)animated {
188196
BOOL isForward = (index > self.currentIndex && [self isLtrLayout]) || (index < self.currentIndex && ![self isLtrLayout]);
189197
UIPageViewControllerNavigationDirection direction = isForward ? UIPageViewControllerNavigationDirectionForward : UIPageViewControllerNavigationDirectionReverse;
190198

199+
long diff = labs(index - _currentIndex);
200+
191201
[self setPagerViewControllers:index
192202
direction:direction
193-
animated:animated];
203+
animated:diff == 0 ? NO : animated];
194204

195205
}
196206

197207
- (void)setPagerViewControllers:(NSInteger)index
198208
direction:(UIPageViewControllerNavigationDirection)direction
199209
animated:(BOOL)animated{
200210
if (_nativePageViewController == nil) {
211+
[self enableSwipe];
201212
return;
202213
}
203214

@@ -207,12 +218,12 @@ - (void)setPagerViewControllers:(NSInteger)index
207218
animated:animated
208219
completion:^(BOOL finished) {
209220
__strong RNCPagerViewComponentView *strongSelf = weakSelf;
221+
[strongSelf enableSwipe];
210222
if (strongSelf->_eventEmitter != nullptr ) {
211223
const auto strongEventEmitter = *std::dynamic_pointer_cast<const RNCViewPagerEventEmitter>(strongSelf->_eventEmitter);
212224
int position = (int) index;
213225
strongEventEmitter.onPageSelected(RNCViewPagerEventEmitter::OnPageSelected{.position = static_cast<double>(position)});
214226
strongSelf->_currentIndex = index;
215-
strongSelf->_nativePageViewController.view.userInteractionEnabled = YES;
216227
}
217228
}];
218229
}

ios/ReactNativePageView.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,13 @@ - (void)setReactViewControllers:(NSInteger)index
153153
animated:(BOOL)animated
154154
shouldCallOnPageSelected:(BOOL)shouldCallOnPageSelected {
155155
if (self.reactPageViewController == nil) {
156+
[self enableSwipe];
156157
return;
157158
}
158159

159160
NSArray *currentVCs = self.reactPageViewController.viewControllers;
160161
if (currentVCs.count == 1 && [currentVCs.firstObject isEqual:controller]) {
162+
[self enableSwipe];
161163
return;
162164
}
163165

@@ -176,9 +178,10 @@ - (void)setReactViewControllers:(NSInteger)index
176178
strongSelf.currentIndex = index;
177179
strongSelf.currentView = controller.view;
178180

181+
[strongSelf enableSwipe];
182+
179183
if (finished) {
180184
strongSelf.animating = NO;
181-
strongSelf.reactPageViewController.view.userInteractionEnabled = YES;
182185
}
183186

184187
if (strongSelf.eventDispatcher) {
@@ -223,10 +226,18 @@ - (void)updateDataSource {
223226
}
224227
}
225228

229+
- (void)disableSwipe {
230+
self.reactPageViewController.view.userInteractionEnabled = NO;
231+
}
232+
233+
- (void)enableSwipe {
234+
self.reactPageViewController.view.userInteractionEnabled = YES;
235+
}
236+
226237
- (void)goTo:(NSInteger)index animated:(BOOL)animated {
227238
NSInteger numberOfPages = self.reactSubviews.count;
228239

229-
_reactPageViewController.view.userInteractionEnabled = NO;
240+
[self disableSwipe];
230241

231242
_destinationIndex = index;
232243

0 commit comments

Comments
 (0)