@@ -41,6 +41,7 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher {
41
41
_coalescingKey = 0 ;
42
42
_eventDispatcher = eventDispatcher;
43
43
_cachedControllers = [NSHashTable weakObjectsHashTable ];
44
+ _overdrag = YES ;
44
45
}
45
46
return self;
46
47
}
@@ -95,9 +96,9 @@ - (void)embed {
95
96
self.scrollView = (UIScrollView *)subview;
96
97
}
97
98
}
98
-
99
+
99
100
self.reactPageViewController = pageViewController;
100
-
101
+
101
102
UIPageControl *pageIndicatorView = [self createPageIndicator ];
102
103
103
104
pageIndicatorView.numberOfPages = self.reactSubviews .count ;
@@ -210,17 +211,17 @@ - (void)goTo:(NSInteger)index animated:(BOOL)animated {
210
211
if (numberOfPages == 0 || index < 0 ) {
211
212
return ;
212
213
}
213
-
214
+
214
215
UIPageViewControllerNavigationDirection direction = (index > self.currentIndex ) ? UIPageViewControllerNavigationDirectionForward : UIPageViewControllerNavigationDirectionReverse;
215
216
216
217
NSInteger indexToDisplay = index < numberOfPages ? index : numberOfPages - 1 ;
217
218
218
219
UIView *viewToDisplay = self.reactSubviews [indexToDisplay];
219
220
UIViewController *controllerToDisplay = [self findAndCacheControllerForView: viewToDisplay];
220
-
221
+
221
222
self.reactPageIndicatorView .numberOfPages = numberOfPages;
222
223
self.reactPageIndicatorView .currentPage = indexToDisplay;
223
-
224
+
224
225
[self setReactViewControllers: indexToDisplay
225
226
with: controllerToDisplay
226
227
direction: direction
@@ -233,12 +234,12 @@ - (UIViewController *)findAndCacheControllerForView:(UIView *)viewToDisplay {
233
234
234
235
UIViewController *controllerToDisplay = [self findCachedControllerForView: viewToDisplay];
235
236
UIViewController *current = [self currentlyDisplayed ];
236
-
237
+
237
238
if (!controllerToDisplay && current.view .reactTag == viewToDisplay.reactTag ) {
238
239
controllerToDisplay = current;
239
240
}
240
241
if (!controllerToDisplay) {
241
- controllerToDisplay = [[UIViewController alloc ] initWithView: viewToDisplay];
242
+ controllerToDisplay = [[UIViewController alloc ] initWithView: viewToDisplay];
242
243
}
243
244
[self .cachedControllers addObject: controllerToDisplay];
244
245
@@ -255,7 +256,7 @@ - (UIViewController *)nextControllerForController:(UIViewController *)controller
255
256
}
256
257
257
258
direction == UIPageViewControllerNavigationDirectionForward ? index++ : index--;
258
-
259
+
259
260
if (index < 0 || (index > (numberOfPages - 1 ))) {
260
261
return nil ;
261
262
}
@@ -334,6 +335,14 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
334
335
335
336
- (void )scrollViewWillEndDragging : (UIScrollView *)scrollView withVelocity : (CGPoint)velocity targetContentOffset : (inout CGPoint *)targetContentOffset {
336
337
[self .eventDispatcher sendEvent: [[RCTOnPageScrollStateChanged alloc ] initWithReactTag: self .reactTag state: @" settling" coalescingKey: _coalescingKey++]];
338
+
339
+ if (!_overdrag) {
340
+ if (_currentIndex == 0 && scrollView.contentOffset .x <= scrollView.bounds .size .width ) {
341
+ *targetContentOffset = CGPointMake (scrollView.bounds .size .width , 0 );
342
+ } else if (_currentIndex == _reactPageIndicatorView.numberOfPages -1 && scrollView.contentOffset .x >= scrollView.bounds .size .width ) {
343
+ *targetContentOffset = CGPointMake (scrollView.bounds .size .width , 0 );
344
+ }
345
+ }
337
346
}
338
347
339
348
- (void )scrollViewDidEndDecelerating : (UIScrollView *)scrollView {
@@ -343,6 +352,15 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
343
352
- (void )scrollViewDidScroll : (UIScrollView *)scrollView {
344
353
CGPoint point = scrollView.contentOffset ;
345
354
float offset = 0 ;
355
+
356
+ if (!_overdrag) {
357
+ if (_currentIndex == 0 && scrollView.contentOffset .x < scrollView.bounds .size .width ) {
358
+ scrollView.contentOffset = CGPointMake (scrollView.bounds .size .width , 0 );
359
+ } else if (_currentIndex == _reactPageIndicatorView.numberOfPages - 1 && scrollView.contentOffset .x > scrollView.bounds .size .width ) {
360
+ scrollView.contentOffset = CGPointMake (scrollView.bounds .size .width , 0 );
361
+ }
362
+ }
363
+
346
364
if (self.orientation == UIPageViewControllerNavigationOrientationHorizontal) {
347
365
if (self.frame .size .width != 0 ) {
348
366
offset = (point.x - self.frame .size .width )/self.frame .size .width ;
0 commit comments