@@ -296,53 +296,52 @@ - (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 ;
313+ BOOL isBeingMovedByNestedScrollView = scrollView.isDecelerating == false && scrollView.isDragging == false ;
314314
315- if (scrollView.isDragging ) {
315+ if (scrollView.isDragging || isBeingMovedByNestedScrollView ) {
316316 _destinationIndex = isAnimatingBackwards ? _currentIndex - 1 : _currentIndex + 1 ;
317317 }
318318
319319 if (isAnimatingBackwards) {
320- position = _destinationIndex;
321- absoluteOffset = fmax (0 , 1 - absoluteOffset);
320+ position = _destinationIndex;
321+ absoluteOffset = fmax (0 , 1 - absoluteOffset);
322322 }
323323
324324 if (!_overdrag) {
325325 NSInteger maxIndex = _nativeChildrenViewControllers.count - 1 ;
326- NSInteger firstPageIndex = ! isHorizontalRtl ? 0 : maxIndex ;
327- NSInteger lastPageIndex = ! isHorizontalRtl ? maxIndex : 0 ;
326+ NSInteger firstPageIndex = isHorizontalRtl ? maxIndex : 0 ;
327+ NSInteger lastPageIndex = isHorizontalRtl ? 0 : maxIndex ;
328328 BOOL isFirstPage = _currentIndex == firstPageIndex;
329329 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 ;
330+ CGFloat topBound = isHorizontal ? scrollView.bounds .size .width : scrollView.bounds .size .height ;
332331
333332 if ((isFirstPage && contentOffset <= topBound) || (isLastPage && contentOffset >= topBound)) {
334- CGPoint croppedOffset = [ self isHorizontal ] ? CGPointMake (topBound, 0 ) : CGPointMake (0 , topBound);
333+ CGPoint croppedOffset = isHorizontal ? CGPointMake (topBound, 0 ) : CGPointMake (0 , topBound);
335334 scrollView.contentOffset = croppedOffset;
336- absoluteOffset= 0 ;
335+ absoluteOffset = 0 ;
337336 position = isLastPage ? lastPageIndex : firstPageIndex;
338337 }
339338 }
340339
341340 float interpolatedOffset = absoluteOffset * labs (_destinationIndex - _currentIndex);
342-
343341 [self sendScrollEventsForPosition: position offset: interpolatedOffset];
344342}
345343
344+
346345#pragma mark - UIPageViewControllerDelegate
347346
348347- (void )pageViewController : (UIPageViewController *)pageViewController
@@ -356,7 +355,6 @@ - (void)pageViewController:(UIPageViewController *)pageViewController
356355 int position = (int ) currentIndex;
357356 const auto eventEmitter = [self pagerEventEmitter ];
358357 eventEmitter->onPageSelected (RNCViewPagerEventEmitter::OnPageSelected{.position = static_cast <double >(position)});
359- eventEmitter->onPageScroll (RNCViewPagerEventEmitter::OnPageScroll{.position = static_cast <double >(position), .offset = 0.0 });
360358 }
361359}
362360
0 commit comments