@@ -296,53 +296,52 @@ - (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 ;
313
+ BOOL isBeingMovedByNestedScrollView = scrollView.isDecelerating == false && scrollView.isDragging == false ;
314
314
315
- if (scrollView.isDragging ) {
315
+ if (scrollView.isDragging || isBeingMovedByNestedScrollView ) {
316
316
_destinationIndex = isAnimatingBackwards ? _currentIndex - 1 : _currentIndex + 1 ;
317
317
}
318
318
319
319
if (isAnimatingBackwards) {
320
- position = _destinationIndex;
321
- absoluteOffset = fmax (0 , 1 - absoluteOffset);
320
+ position = _destinationIndex;
321
+ absoluteOffset = fmax (0 , 1 - absoluteOffset);
322
322
}
323
323
324
324
if (!_overdrag) {
325
325
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 ;
328
328
BOOL isFirstPage = _currentIndex == firstPageIndex;
329
329
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 ;
332
331
333
332
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);
335
334
scrollView.contentOffset = croppedOffset;
336
- absoluteOffset= 0 ;
335
+ absoluteOffset = 0 ;
337
336
position = isLastPage ? lastPageIndex : firstPageIndex;
338
337
}
339
338
}
340
339
341
340
float interpolatedOffset = absoluteOffset * labs (_destinationIndex - _currentIndex);
342
-
343
341
[self sendScrollEventsForPosition: position offset: interpolatedOffset];
344
342
}
345
343
344
+
346
345
#pragma mark - UIPageViewControllerDelegate
347
346
348
347
- (void )pageViewController : (UIPageViewController *)pageViewController
@@ -356,7 +355,6 @@ - (void)pageViewController:(UIPageViewController *)pageViewController
356
355
int position = (int ) currentIndex;
357
356
const auto eventEmitter = [self pagerEventEmitter ];
358
357
eventEmitter->onPageSelected (RNCViewPagerEventEmitter::OnPageSelected{.position = static_cast <double >(position)});
359
- eventEmitter->onPageScroll (RNCViewPagerEventEmitter::OnPageScroll{.position = static_cast <double >(position), .offset = 0.0 });
360
358
}
361
359
}
362
360
0 commit comments