@@ -32,7 +32,7 @@ - (instancetype) initWithReactTag:(NSNumber *)reactTag
32
32
coalescingKey : (uint16_t )coalescingKey ;
33
33
{
34
34
RCTAssertParam (reactTag);
35
-
35
+
36
36
if ((self = [super init ])) {
37
37
_viewTag = reactTag;
38
38
_position = position;
@@ -99,7 +99,7 @@ - (instancetype) initWithReactTag:(NSNumber *)reactTag
99
99
coalescingKey : (uint16_t )coalescingKey ;
100
100
{
101
101
RCTAssertParam (reactTag);
102
-
102
+
103
103
if ((self = [super init ])) {
104
104
_viewTag = reactTag;
105
105
_state = state;
@@ -165,7 +165,7 @@ - (instancetype) initWithReactTag:(NSNumber *)reactTag
165
165
coalescingKey : (uint16_t )coalescingKey ;
166
166
{
167
167
RCTAssertParam (reactTag);
168
-
168
+
169
169
if ((self = [super init ])) {
170
170
_viewTag = reactTag;
171
171
_position = position;
@@ -222,6 +222,7 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher {
222
222
_dismissKeyboard = UIScrollViewKeyboardDismissModeNone;
223
223
_coalescingKey = 0 ;
224
224
_eventDispatcher = eventDispatcher;
225
+ _overdrag = YES ;
225
226
}
226
227
return self;
227
228
}
@@ -259,7 +260,7 @@ - (void)addPages {
259
260
_childrenViewControllers = tempChildrenViewControllers;
260
261
_reactPageIndicatorView.numberOfPages = _childrenViewControllers.count ;
261
262
[self goTo: [NSNumber numberWithInteger: _currentIndex] animated: NO ];
262
-
263
+
263
264
} else {
264
265
RCTLog (@" getParentViewController returns nil" );
265
266
}
@@ -271,36 +272,36 @@ - (void)embed {
271
272
dictionaryWithObjectsAndKeys:
272
273
[NSNumber numberWithLong: _pageMargin],
273
274
UIPageViewControllerOptionInterPageSpacingKey, nil ];
274
-
275
+
275
276
UIPageViewController *reactPageViewController =
276
277
[[UIPageViewController alloc ]
277
278
initWithTransitionStyle: _transitionStyle
278
279
navigationOrientation: _orientation
279
280
options: options];
280
-
281
+
281
282
_reactPageViewController = reactPageViewController;
282
283
_reactPageViewController.delegate = self;
283
284
_reactPageViewController.dataSource = self;
284
-
285
+
285
286
for (UIView *subview in _reactPageViewController.view .subviews ) {
286
287
if ([subview isKindOfClass: UIScrollView.class]){
287
288
((UIScrollView *)subview).delegate = self;
288
289
((UIScrollView *)subview).keyboardDismissMode = _dismissKeyboard;
289
290
}
290
291
}
291
-
292
+
292
293
[self renderChildrenViewControllers ];
293
294
_reactPageIndicatorView = [self createPageIndicator: self ];
294
295
_reactPageIndicatorView.hidden = !_showPageIndicator;
295
-
296
+
296
297
[[self reactViewController ] addChildViewController: _reactPageViewController];
297
298
[reactPageViewController.view addSubview: _reactPageIndicatorView];
298
299
[self addSubview: reactPageViewController.view];
299
300
_reactPageViewController.view .frame = [self bounds ];
300
-
301
+
301
302
[_reactPageViewController didMoveToParentViewController: [self reactViewController ]];
302
303
[self shouldScroll: _scrollEnabled];
303
-
304
+
304
305
// Add the page view controller's gesture recognizers to the view controller's view so that the gestures are started more easily.
305
306
self.gestureRecognizers = _reactPageViewController.gestureRecognizers ;
306
307
_reactPageIndicatorView.translatesAutoresizingMaskIntoConstraints = NO ;
@@ -341,7 +342,7 @@ - (void)renderChildrenViewControllers {
341
342
[vc.view removeFromSuperview ];
342
343
}
343
344
[_childrenViewControllers removeAllObjects ];
344
-
345
+
345
346
for (UIView *view in [self reactSubviews ]) {
346
347
[view removeFromSuperview ];
347
348
UIViewController *pageViewController = [self createChildViewController: view];
@@ -372,7 +373,7 @@ - (void)setReactViewControllers:(NSInteger)index
372
373
if (weakSelf.eventDispatcher ) {
373
374
[weakSelf.eventDispatcher sendEvent: [[RCTOnPageSelected alloc ] initWithReactTag: weakSelf.reactTag position: [NSNumber numberWithInteger: index] coalescingKey: coalescingKey]];
374
375
}
375
-
376
+
376
377
}];
377
378
}
378
379
@@ -385,20 +386,20 @@ - (UIViewController *)createChildViewController:(UIView *)view {
385
386
- (void )goTo : (NSNumber *)index animated : (BOOL )animated {
386
387
if (_currentIndex >= 0 &&
387
388
index.integerValue < _childrenViewControllers.count ) {
388
-
389
+
389
390
_reactPageIndicatorView.currentPage = index.integerValue ;
390
391
UIPageViewControllerNavigationDirection direction =
391
392
(index.integerValue > _currentIndex)
392
393
? UIPageViewControllerNavigationDirectionForward
393
394
: UIPageViewControllerNavigationDirectionReverse;
394
-
395
+
395
396
UIViewController *viewController =
396
397
[_childrenViewControllers objectAtIndex: index.integerValue];
397
398
[self setReactViewControllers: index.integerValue
398
399
with: viewController
399
400
direction: direction
400
401
animated: animated];
401
-
402
+
402
403
}
403
404
}
404
405
@@ -424,7 +425,7 @@ - (void)pageViewController:(UIPageViewController *)pageViewController
424
425
UIViewController* currentVC = pageViewController.viewControllers [0 ];
425
426
_currentIndex = [_childrenViewControllers indexOfObject: currentVC];
426
427
[_eventDispatcher sendEvent: [[RCTOnPageSelected alloc ] initWithReactTag: self .reactTag position: [NSNumber numberWithInteger: _currentIndex] coalescingKey: _coalescingKey++]];
427
-
428
+
428
429
[_eventDispatcher sendEvent: [[RCTOnPageScrollEvent alloc ] initWithReactTag: self .reactTag position: [NSNumber numberWithInteger: _currentIndex] offset: [NSNumber numberWithFloat: 0 ] coalescingKey: _coalescingKey++]];
429
430
_reactPageIndicatorView.currentPage = _currentIndex;
430
431
}
@@ -435,13 +436,13 @@ - (UIViewController *)pageViewController:
435
436
(UIPageViewController *)pageViewController
436
437
viewControllerAfterViewController : (UIViewController *)viewController {
437
438
NSUInteger index = [_childrenViewControllers indexOfObject: viewController];
438
-
439
+
439
440
if (index == NSNotFound ) {
440
441
return nil ;
441
442
}
442
-
443
+
443
444
index++;
444
-
445
+
445
446
if (index == [_childrenViewControllers count ]) {
446
447
return nil ;
447
448
}
@@ -454,15 +455,15 @@ - (UIViewController *)pageViewController:
454
455
(UIPageViewController *)pageViewController
455
456
viewControllerBeforeViewController : (UIViewController *)viewController {
456
457
NSUInteger index = [_childrenViewControllers indexOfObject: viewController];
457
-
458
+
458
459
if (index == NSNotFound ) {
459
460
return nil ;
460
461
}
461
-
462
+
462
463
if (index == 0 ) {
463
464
return nil ;
464
465
}
465
-
466
+
466
467
index--;
467
468
return [_childrenViewControllers objectAtIndex: index];
468
469
}
@@ -504,6 +505,13 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
504
505
}
505
506
506
507
- (void )scrollViewWillEndDragging : (UIScrollView *)scrollView withVelocity : (CGPoint)velocity targetContentOffset : (inout CGPoint *)targetContentOffset {
508
+ if (!_overdrag) {
509
+ if (_currentIndex == 0 && scrollView.contentOffset .x <= scrollView.bounds .size .width ) {
510
+ *targetContentOffset = CGPointMake (scrollView.bounds .size .width , 0 );
511
+ } else if (_currentIndex == _reactPageIndicatorView.numberOfPages -1 && scrollView.contentOffset .x >= scrollView.bounds .size .width ) {
512
+ *targetContentOffset = CGPointMake (scrollView.bounds .size .width , 0 );
513
+ }
514
+ }
507
515
[_eventDispatcher sendEvent: [[RCTOnPageScrollStateChanged alloc ] initWithReactTag: self .reactTag state: @" settling" coalescingKey: _coalescingKey++]];
508
516
}
509
517
@@ -512,6 +520,14 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
512
520
}
513
521
514
522
- (void )scrollViewDidScroll : (UIScrollView *)scrollView {
523
+ if (!_overdrag) {
524
+ if (_currentIndex == 0 && scrollView.contentOffset .x < scrollView.bounds .size .width ) {
525
+ scrollView.contentOffset = CGPointMake (scrollView.bounds .size .width , 0 );
526
+ } else if (_currentIndex == _reactPageIndicatorView.numberOfPages -1 && scrollView.contentOffset .x > scrollView.bounds .size .width ) {
527
+ scrollView.contentOffset = CGPointMake (scrollView.bounds .size .width , 0 );
528
+ }
529
+ }
530
+
515
531
CGPoint point = scrollView.contentOffset ;
516
532
float offset = (point.x - self.frame .size .width )/self.frame .size .width ;
517
533
if (fabs (offset) > 1 ) {
0 commit comments