@@ -159,14 +159,16 @@ - (void)setupInitialController {
159
159
[self setReactViewControllers: self .initialPage
160
160
with: initialController
161
161
direction: UIPageViewControllerNavigationDirectionForward
162
- animated: YES ];
162
+ animated: YES
163
+ shouldCallOnPageSelected: YES ];
163
164
}
164
165
}
165
166
166
167
- (void )setReactViewControllers : (NSInteger )index
167
168
with : (UIViewController *)controller
168
169
direction : (UIPageViewControllerNavigationDirection)direction
169
- animated : (BOOL )animated {
170
+ animated : (BOOL )animated
171
+ shouldCallOnPageSelected : (BOOL )shouldCallOnPageSelected {
170
172
if (self.reactPageViewController == nil ) {
171
173
return ;
172
174
}
@@ -183,7 +185,9 @@ - (void)setReactViewControllers:(NSInteger)index
183
185
184
186
if (strongSelf.eventDispatcher ) {
185
187
if (strongSelf.lastReportedIndex != strongSelf.currentIndex ) {
186
- [strongSelf.eventDispatcher sendEvent: [[RCTOnPageSelected alloc ] initWithReactTag: strongSelf.reactTag position: @(index) coalescingKey: coalescingKey]];
188
+ if (shouldCallOnPageSelected) {
189
+ [strongSelf.eventDispatcher sendEvent: [[RCTOnPageSelected alloc ] initWithReactTag: strongSelf.reactTag position: @(index) coalescingKey: coalescingKey]];
190
+ }
187
191
strongSelf.lastReportedIndex = strongSelf.currentIndex ;
188
192
}
189
193
}
@@ -236,33 +240,39 @@ - (void)goTo:(NSInteger)index animated:(BOOL)animated {
236
240
long diff = labs (index - _currentIndex);
237
241
238
242
if (isForward && diff > 0 ) {
239
- for (NSInteger i=_currentIndex+1 ; i<=index; i++) {
240
- [self goToViewController: i direction: direction animated: animated];
243
+ for (NSInteger i=_currentIndex; i<=index; i++) {
244
+ if (i == _currentIndex) {
245
+ continue ;
246
+ }
247
+ [self goToViewController: i direction: direction animated: animated shouldCallOnPageSelected: i == index];
241
248
}
242
249
}
243
250
244
251
if (!isForward && diff > 0 ) {
245
- for (NSInteger i=_currentIndex- 1 ; i>=index; i--) {
246
- if (i >= 0 ) {
247
- [ self goToViewController: i direction: direction animated: animated] ;
252
+ for (NSInteger i=_currentIndex; i>=index; i--) {
253
+ if (index == _currentIndex ) {
254
+ continue ;
248
255
}
256
+ [self goToViewController: i direction: direction animated: animated shouldCallOnPageSelected: i == index];
249
257
}
250
258
}
251
259
252
260
if (diff == 0 ) {
253
- [self goToViewController: index direction: direction animated: animated];
261
+ [self goToViewController: index direction: direction animated: animated shouldCallOnPageSelected: YES ];
254
262
}
255
263
}
256
264
257
265
- (void )goToViewController : (NSInteger )index
258
266
direction : (UIPageViewControllerNavigationDirection)direction
259
- animated : (BOOL )animated {
267
+ animated : (BOOL )animated
268
+ shouldCallOnPageSelected : (BOOL )shouldCallOnPageSelected {
260
269
UIView *viewToDisplay = self.reactSubviews [index];
261
270
UIViewController *controllerToDisplay = [self findAndCacheControllerForView: viewToDisplay];
262
271
[self setReactViewControllers: index
263
272
with: controllerToDisplay
264
273
direction: direction
265
- animated: animated];
274
+ animated: animated
275
+ shouldCallOnPageSelected: shouldCallOnPageSelected];
266
276
}
267
277
268
278
- (UIViewController *)findAndCacheControllerForView : (UIView *)viewToDisplay {
@@ -320,7 +330,6 @@ - (void)pageViewController:(UIPageViewController *)pageViewController
320
330
self.currentIndex = currentIndex;
321
331
self.currentView = currentVC.view ;
322
332
self.reactPageIndicatorView .currentPage = currentIndex;
323
-
324
333
[self .eventDispatcher sendEvent: [[RCTOnPageSelected alloc ] initWithReactTag: self .reactTag position: @(currentIndex) coalescingKey: _coalescingKey++]];
325
334
[self .eventDispatcher sendEvent: [[RCTOnPageScrollEvent alloc ] initWithReactTag: self .reactTag position: @(currentIndex) offset: @(0.0 )]];
326
335
self.lastReportedIndex = currentIndex;
0 commit comments