@@ -231,13 +231,13 @@ - (void)layoutSubviews {
231
231
if (_reactPageViewController) {
232
232
[self shouldScroll: _scrollEnabled];
233
233
// Below line fix bug, where the view does not update after orientation changed.
234
- [self goTo: [ NSNumber numberWithInteger: _currentIndex] animated: NO ];
234
+ [self goTo: @( _currentIndex) animated: NO ];
235
235
} else {
236
236
[self embed ];
237
237
}
238
238
}
239
239
240
- - (void )didUpdateReactSubviews {
240
+ - (void )didUpdateReactSubviews {
241
241
if (_childrenViewControllers.count == 0 ){
242
242
return ;
243
243
}
@@ -258,7 +258,7 @@ - (void)addPages {
258
258
}
259
259
_childrenViewControllers = tempChildrenViewControllers;
260
260
_reactPageIndicatorView.numberOfPages = _childrenViewControllers.count ;
261
- [self goTo: [ NSNumber numberWithInteger: _currentIndex] animated: NO ];
261
+ [self goTo: @( _currentIndex) animated: NO ];
262
262
263
263
} else {
264
264
RCTLog (@" getParentViewController returns nil" );
@@ -365,16 +365,16 @@ - (void)setReactViewControllers:(NSInteger)index
365
365
__weak ReactNativePageView *weakSelf = self;
366
366
uint16_t coalescingKey = _coalescingKey++;
367
367
[_reactPageViewController
368
- setViewControllers: [ NSArray arrayWithObjects: pageViewController, nil ]
368
+ setViewControllers: @[ pageViewController]
369
369
direction: direction
370
370
animated: animated
371
371
completion: ^(BOOL finished) {
372
- weakSelf.currentIndex = index;
373
- if (weakSelf.eventDispatcher ) {
374
- [weakSelf.eventDispatcher sendEvent: [[RCTOnPageSelected alloc ] initWithReactTag: weakSelf.reactTag position: [NSNumber numberWithInteger: index] coalescingKey: coalescingKey]];
375
- }
376
-
377
- }];
372
+ weakSelf.currentIndex = index;
373
+ if (weakSelf.eventDispatcher ) {
374
+ [weakSelf.eventDispatcher sendEvent: [[RCTOnPageSelected alloc ] initWithReactTag: weakSelf.reactTag position: [NSNumber numberWithInteger: index] coalescingKey: coalescingKey]];
375
+ }
376
+
377
+ }];
378
378
}
379
379
380
380
- (UIViewController *)createChildViewController : (UIView *)view {
@@ -384,22 +384,21 @@ - (UIViewController *)createChildViewController:(UIView *)view {
384
384
}
385
385
386
386
- (void )goTo : (NSNumber *)index animated : (BOOL )animated {
387
- if (_currentIndex >= 0 &&
388
- index.integerValue < _childrenViewControllers.count ) {
389
-
390
- _reactPageIndicatorView.currentPage = index.integerValue ;
387
+ if (_currentIndex >= 0 ) {
391
388
UIPageViewControllerNavigationDirection direction =
392
389
(index.integerValue > _currentIndex)
393
390
? UIPageViewControllerNavigationDirectionForward
394
391
: UIPageViewControllerNavigationDirectionReverse;
395
392
396
- UIViewController *viewController =
397
- [_childrenViewControllers objectAtIndex: index.integerValue];
398
- [self setReactViewControllers: index.integerValue
399
- with: viewController
393
+
394
+ NSInteger indexToDisplay = index.integerValue < _childrenViewControllers.count ? index.integerValue : _childrenViewControllers.count - 1 ;
395
+ UIViewController *controllerToDisplay = _childrenViewControllers[indexToDisplay];
396
+ _reactPageIndicatorView.currentPage = indexToDisplay;
397
+
398
+ [self setReactViewControllers: indexToDisplay
399
+ with: controllerToDisplay
400
400
direction: direction
401
401
animated: animated];
402
-
403
402
}
404
403
}
405
404
@@ -478,8 +477,6 @@ - (void)shouldShowPageIndicator:(BOOL)showPageIndicator {
478
477
}
479
478
480
479
- (UIPageControl *)createPageIndicator : (UIView *)parentView {
481
- CGPoint parentOrigin = parentView.frame .origin ;
482
- CGSize parentSize = parentView.frame .size ;
483
480
UIPageControl *pageControl = [[UIPageControl alloc ] init ];
484
481
pageControl.numberOfPages = _childrenViewControllers.count ;
485
482
pageControl.currentPage = _initialPage;
@@ -522,4 +519,3 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
522
519
}
523
520
524
521
@end
525
-
0 commit comments