Skip to content

Commit 8a7b254

Browse files
AlmouroPiotr Trocki
authored andcommitted
fix(ios): onPageSelected is called too often (#170)
1 parent dfce3d0 commit 8a7b254

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

ios/ReactNativePageView.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,12 +422,14 @@ - (void)pageViewController:(UIPageViewController *)pageViewController
422422
didFinishAnimating:(BOOL)finished
423423
previousViewControllers: (nonnull NSArray<UIViewController *> *)previousViewControllers
424424
transitionCompleted:(BOOL)completed {
425-
UIViewController* currentVC = pageViewController.viewControllers[0];
426-
_currentIndex = [_childrenViewControllers indexOfObject:currentVC];
427-
[_eventDispatcher sendEvent:[[RCTOnPageSelected alloc] initWithReactTag:self.reactTag position:[NSNumber numberWithInteger:_currentIndex] coalescingKey:_coalescingKey++]];
428-
429-
[_eventDispatcher sendEvent:[[RCTOnPageScrollEvent alloc] initWithReactTag:self.reactTag position:[NSNumber numberWithInteger:_currentIndex] offset:[NSNumber numberWithFloat:0] coalescingKey:_coalescingKey++]];
430-
_reactPageIndicatorView.currentPage = _currentIndex;
425+
if (completed) {
426+
UIViewController* currentVC = pageViewController.viewControllers[0];
427+
_currentIndex = [_childrenViewControllers indexOfObject:currentVC];
428+
[_eventDispatcher sendEvent:[[RCTOnPageSelected alloc] initWithReactTag:self.reactTag position:[NSNumber numberWithInteger:_currentIndex] coalescingKey:_coalescingKey++]];
429+
430+
[_eventDispatcher sendEvent:[[RCTOnPageScrollEvent alloc] initWithReactTag:self.reactTag position:[NSNumber numberWithInteger:_currentIndex] offset:[NSNumber numberWithFloat:0] coalescingKey:_coalescingKey++]];
431+
_reactPageIndicatorView.currentPage = _currentIndex;
432+
}
431433
}
432434

433435
#pragma mark - Datasource After

0 commit comments

Comments
 (0)