Skip to content

Commit 12ece8d

Browse files
authored
fix: set last/first page as idling when dragging (#682)
* fix: set last/first page as idling when dragging * fix: adjust fabric implementation
1 parent 899705b commit 12ece8d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

ios/Fabric/RNCPagerViewComponentView.mm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
260260

261261
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
262262

263+
const auto strongEventEmitter = *std::dynamic_pointer_cast<const RNCViewPagerEventEmitter>(_eventEmitter);
264+
strongEventEmitter.onPageScrollStateChanged(RNCViewPagerEventEmitter::OnPageScrollStateChanged{.pageScrollState = RNCViewPagerEventEmitter::OnPageScrollStateChangedPageScrollState::Settling });
265+
263266
if (!_overdrag) {
264267
NSInteger maxIndex = _nativeChildrenViewControllers.count - 1;
265268
BOOL isFirstPage = [self isLtrLayout] ? _currentIndex == 0 : _currentIndex == maxIndex;
@@ -270,11 +273,12 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi
270273
if ((isFirstPage && contentOffset <= topBound) || (isLastPage && contentOffset >= topBound)) {
271274
CGPoint croppedOffset = [self isHorizontal] ? CGPointMake(topBound, 0) : CGPointMake(0, topBound);
272275
*targetContentOffset = croppedOffset;
276+
277+
strongEventEmitter.onPageScrollStateChanged(RNCViewPagerEventEmitter::OnPageScrollStateChanged{.pageScrollState = RNCViewPagerEventEmitter::OnPageScrollStateChangedPageScrollState::Idle });
273278
}
274279
}
275280

276-
const auto strongEventEmitter = *std::dynamic_pointer_cast<const RNCViewPagerEventEmitter>(_eventEmitter);
277-
strongEventEmitter.onPageScrollStateChanged(RNCViewPagerEventEmitter::OnPageScrollStateChanged{.pageScrollState = RNCViewPagerEventEmitter::OnPageScrollStateChangedPageScrollState::Settling });
281+
278282
}
279283

280284
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {

ios/ReactNativePageView.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi
375375
if ((isFirstPage && contentOffset <= topBound) || (isLastPage && contentOffset >= topBound)) {
376376
CGPoint croppedOffset = [self isHorizontal] ? CGPointMake(topBound, 0) : CGPointMake(0, topBound);
377377
*targetContentOffset = croppedOffset;
378+
379+
[self.eventDispatcher sendEvent:[[RCTOnPageScrollStateChanged alloc] initWithReactTag:self.reactTag state:@"idle" coalescingKey:_coalescingKey++]];
378380
}
379381
}
380382
}

0 commit comments

Comments
 (0)