@@ -296,53 +296,51 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
296
296
297
297
298
298
- (void )scrollViewDidScroll : (UIScrollView *)scrollView {
299
- CGFloat contentOffset = [self isHorizontal ] ? scrollView.contentOffset .x : scrollView.contentOffset .y ;
300
- CGFloat frameSize = [self isHorizontal ] ? scrollView.frame .size .width : scrollView.frame .size .height ;
301
-
299
+ BOOL isHorizontal = [self isHorizontal ];
300
+ CGFloat contentOffset = isHorizontal ? scrollView.contentOffset .x : scrollView.contentOffset .y ;
301
+ CGFloat frameSize = isHorizontal ? scrollView.frame .size .width : scrollView.frame .size .height ;
302
+
302
303
if (frameSize == 0 ) {
303
304
return ;
304
305
}
305
306
306
- float offset = (contentOffset - frameSize)/frameSize;
307
-
307
+ float offset = (contentOffset - frameSize) / frameSize;
308
308
float absoluteOffset = fabs (offset);
309
-
310
309
NSInteger position = _currentIndex;
311
310
312
311
BOOL isHorizontalRtl = [self isHorizontalRtlLayout ];
313
312
BOOL isAnimatingBackwards = isHorizontalRtl ? offset > 0 .05f : offset < 0 ;
314
-
315
- if (scrollView.isDragging ) {
313
+ BOOL isBeingMovedByNestedScrollView = !scrollView. isDragging && !scrollView. isTracking ;
314
+ if (scrollView.isDragging || isBeingMovedByNestedScrollView ) {
316
315
_destinationIndex = isAnimatingBackwards ? _currentIndex - 1 : _currentIndex + 1 ;
317
316
}
318
317
319
318
if (isAnimatingBackwards) {
320
- position = _destinationIndex;
321
- absoluteOffset = fmax (0 , 1 - absoluteOffset);
319
+ position = _destinationIndex;
320
+ absoluteOffset = fmax (0 , 1 - absoluteOffset);
322
321
}
323
322
324
323
if (!_overdrag) {
325
324
NSInteger maxIndex = _nativeChildrenViewControllers.count - 1 ;
326
- NSInteger firstPageIndex = ! isHorizontalRtl ? 0 : maxIndex ;
327
- NSInteger lastPageIndex = ! isHorizontalRtl ? maxIndex : 0 ;
325
+ NSInteger firstPageIndex = isHorizontalRtl ? maxIndex : 0 ;
326
+ NSInteger lastPageIndex = isHorizontalRtl ? 0 : maxIndex ;
328
327
BOOL isFirstPage = _currentIndex == firstPageIndex;
329
328
BOOL isLastPage = _currentIndex == lastPageIndex;
330
- CGFloat contentOffset =[self isHorizontal ] ? scrollView.contentOffset .x : scrollView.contentOffset .y ;
331
- CGFloat topBound = [self isHorizontal ] ? scrollView.bounds .size .width : scrollView.bounds .size .height ;
329
+ CGFloat topBound = isHorizontal ? scrollView.bounds .size .width : scrollView.bounds .size .height ;
332
330
333
331
if ((isFirstPage && contentOffset <= topBound) || (isLastPage && contentOffset >= topBound)) {
334
- CGPoint croppedOffset = [ self isHorizontal ] ? CGPointMake (topBound, 0 ) : CGPointMake (0 , topBound);
332
+ CGPoint croppedOffset = isHorizontal ? CGPointMake (topBound, 0 ) : CGPointMake (0 , topBound);
335
333
scrollView.contentOffset = croppedOffset;
336
- absoluteOffset= 0 ;
334
+ absoluteOffset = 0 ;
337
335
position = isLastPage ? lastPageIndex : firstPageIndex;
338
336
}
339
337
}
340
338
341
339
float interpolatedOffset = absoluteOffset * labs (_destinationIndex - _currentIndex);
342
-
343
340
[self sendScrollEventsForPosition: position offset: interpolatedOffset];
344
341
}
345
342
343
+
346
344
#pragma mark - UIPageViewControllerDelegate
347
345
348
346
- (void )pageViewController : (UIPageViewController *)pageViewController
@@ -356,7 +354,6 @@ - (void)pageViewController:(UIPageViewController *)pageViewController
356
354
int position = (int ) currentIndex;
357
355
const auto eventEmitter = [self pagerEventEmitter ];
358
356
eventEmitter->onPageSelected (RNCViewPagerEventEmitter::OnPageSelected{.position = static_cast <double >(position)});
359
- eventEmitter->onPageScroll (RNCViewPagerEventEmitter::OnPageScroll{.position = static_cast <double >(position), .offset = 0.0 });
360
357
}
361
358
}
362
359
0 commit comments