@@ -296,53 +296,51 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
296296
297297
298298- (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+
302303 if (frameSize == 0 ) {
303304 return ;
304305 }
305306
306- float offset = (contentOffset - frameSize)/frameSize;
307-
307+ float offset = (contentOffset - frameSize) / frameSize;
308308 float absoluteOffset = fabs (offset);
309-
310309 NSInteger position = _currentIndex;
311310
312311 BOOL isHorizontalRtl = [self isHorizontalRtlLayout ];
313312 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 ) {
316315 _destinationIndex = isAnimatingBackwards ? _currentIndex - 1 : _currentIndex + 1 ;
317316 }
318317
319318 if (isAnimatingBackwards) {
320- position = _destinationIndex;
321- absoluteOffset = fmax (0 , 1 - absoluteOffset);
319+ position = _destinationIndex;
320+ absoluteOffset = fmax (0 , 1 - absoluteOffset);
322321 }
323322
324323 if (!_overdrag) {
325324 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 ;
328327 BOOL isFirstPage = _currentIndex == firstPageIndex;
329328 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 ;
332330
333331 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);
335333 scrollView.contentOffset = croppedOffset;
336- absoluteOffset= 0 ;
334+ absoluteOffset = 0 ;
337335 position = isLastPage ? lastPageIndex : firstPageIndex;
338336 }
339337 }
340338
341339 float interpolatedOffset = absoluteOffset * labs (_destinationIndex - _currentIndex);
342-
343340 [self sendScrollEventsForPosition: position offset: interpolatedOffset];
344341}
345342
343+
346344#pragma mark - UIPageViewControllerDelegate
347345
348346- (void )pageViewController : (UIPageViewController *)pageViewController
@@ -356,7 +354,6 @@ - (void)pageViewController:(UIPageViewController *)pageViewController
356354 int position = (int ) currentIndex;
357355 const auto eventEmitter = [self pagerEventEmitter ];
358356 eventEmitter->onPageSelected (RNCViewPagerEventEmitter::OnPageSelected{.position = static_cast <double >(position)});
359- eventEmitter->onPageScroll (RNCViewPagerEventEmitter::OnPageScroll{.position = static_cast <double >(position), .offset = 0.0 });
360357 }
361358}
362359
0 commit comments