@@ -36,7 +36,7 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher {
36
36
if (self = [super init ]) {
37
37
_scrollEnabled = YES ;
38
38
_pageMargin = 0 ;
39
- _previousIndex = -1 ;
39
+ _lastReportedIndex = -1 ;
40
40
_transitionStyle = UIPageViewControllerTransitionStyleScroll;
41
41
_orientation = UIPageViewControllerNavigationOrientationHorizontal;
42
42
_currentIndex = 0 ;
@@ -169,17 +169,16 @@ - (void)setReactViewControllers:(NSInteger)index
169
169
direction: direction
170
170
animated: animated
171
171
completion: ^(BOOL finished) {
172
+ __strong typeof (self) strongSelf = weakSelf;
173
+ strongSelf.currentIndex = index;
174
+ strongSelf.currentView = controller.view ;
172
175
173
- weakSelf.currentIndex = index;
174
- weakSelf.currentView = controller.view ;
175
-
176
- if (weakSelf.eventDispatcher ) {
177
- if (_previousIndex != _currentIndex){
178
- [weakSelf.eventDispatcher sendEvent: [[RCTOnPageSelected alloc ] initWithReactTag: weakSelf.reactTag position: @(index) coalescingKey: coalescingKey]];
176
+ if (strongSelf.eventDispatcher ) {
177
+ if (strongSelf.lastReportedIndex != strongSelf.currentIndex ) {
178
+ [strongSelf.eventDispatcher sendEvent: [[RCTOnPageSelected alloc ] initWithReactTag: strongSelf.reactTag position: @(index) coalescingKey: coalescingKey]];
179
+ strongSelf.lastReportedIndex = strongSelf.currentIndex ;
179
180
}
180
- _previousIndex = _currentIndex;
181
181
}
182
-
183
182
}];
184
183
}
185
184
@@ -284,12 +283,12 @@ - (void)pageViewController:(UIPageViewController *)pageViewController
284
283
NSUInteger currentIndex = [self .reactSubviews indexOfObject: currentVC.view];
285
284
286
285
self.currentIndex = currentIndex;
287
- self.previousIndex = currentIndex - 1 ;
288
286
self.currentView = currentVC.view ;
289
287
self.reactPageIndicatorView .currentPage = currentIndex;
290
288
291
289
[self .eventDispatcher sendEvent: [[RCTOnPageSelected alloc ] initWithReactTag: self .reactTag position: @(currentIndex) coalescingKey: _coalescingKey++]];
292
290
[self .eventDispatcher sendEvent: [[RCTOnPageScrollEvent alloc ] initWithReactTag: self .reactTag position: @(currentIndex) offset: @(0.0 )]];
291
+ self.lastReportedIndex = currentIndex;
293
292
}
294
293
}
295
294
0 commit comments