@@ -342,10 +342,14 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi
342
342
[self .eventDispatcher sendEvent: [[RCTOnPageScrollStateChanged alloc ] initWithReactTag: self .reactTag state: @" settling" coalescingKey: _coalescingKey++]];
343
343
344
344
if (!_overdrag) {
345
- if (_currentIndex == 0 && scrollView.contentOffset .x <= scrollView.bounds .size .width ) {
346
- *targetContentOffset = CGPointMake (scrollView.bounds .size .width , 0 );
347
- } else if (_currentIndex == _reactPageIndicatorView.numberOfPages -1 && scrollView.contentOffset .x >= scrollView.bounds .size .width ) {
348
- *targetContentOffset = CGPointMake (scrollView.bounds .size .width , 0 );
345
+ BOOL isFirstPage = _currentIndex == 0 ;
346
+ BOOL isLastPage = _currentIndex == _reactPageIndicatorView.numberOfPages - 1 ;
347
+ CGFloat contentOffset =[self isHorizontal ] ? scrollView.contentOffset .x : scrollView.contentOffset .y ;
348
+ CGFloat topBound = [self isHorizontal ] ? scrollView.bounds .size .width : scrollView.bounds .size .height ;
349
+
350
+ if ((isFirstPage && contentOffset <= topBound) || (isLastPage && contentOffset >= topBound)) {
351
+ CGPoint croppedOffset = [self isHorizontal ] ? CGPointMake (topBound, 0 ) : CGPointMake (0 , topBound);
352
+ *targetContentOffset = croppedOffset;
349
353
}
350
354
}
351
355
}
@@ -383,11 +387,14 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
383
387
}
384
388
385
389
if (!_overdrag) {
386
- if (_currentIndex == 0 && scrollView.contentOffset .x < scrollView.bounds .size .width ) {
387
- scrollView.contentOffset = CGPointMake (scrollView.bounds .size .width , 0 );
388
- absoluteOffset=0 ;
389
- } else if (_currentIndex == _reactPageIndicatorView.numberOfPages - 1 && scrollView.contentOffset .x > scrollView.bounds .size .width ) {
390
- scrollView.contentOffset = CGPointMake (scrollView.bounds .size .width , 0 );
390
+ BOOL isFirstPage = _currentIndex == 0 ;
391
+ BOOL isLastPage = _currentIndex == _reactPageIndicatorView.numberOfPages - 1 ;
392
+ CGFloat contentOffset =[self isHorizontal ] ? scrollView.contentOffset .x : scrollView.contentOffset .y ;
393
+ CGFloat topBound = [self isHorizontal ] ? scrollView.bounds .size .width : scrollView.bounds .size .height ;
394
+
395
+ if ((isFirstPage && contentOffset <= topBound) || (isLastPage && contentOffset >= topBound)) {
396
+ CGPoint croppedOffset = [self isHorizontal ] ? CGPointMake (topBound, 0 ) : CGPointMake (0 , topBound);
397
+ scrollView.contentOffset = croppedOffset;
391
398
absoluteOffset=0 ;
392
399
}
393
400
}
0 commit comments