Skip to content

Commit 45d10cc

Browse files
author
Piotr Trocki
committed
feat: implement onPageScrollStateChanged
1 parent 766dbd6 commit 45d10cc

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

ios/ReactNativePageView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ NS_ASSUME_NONNULL_BEGIN
2121
@property(nonatomic) UIPageViewControllerNavigationOrientation orientation;
2222
@property(nonatomic, copy) RCTBubblingEventBlock onPageSelected;
2323
@property(nonatomic, copy) RCTBubblingEventBlock onPageScroll;
24+
@property(nonatomic, copy) RCTBubblingEventBlock onPageScrollStateChanged;
25+
2426

2527
- (void)goTo:(NSNumber *)index animated:(BOOL)animated;
2628
- (void)shouldScroll:(BOOL)scrollEnabled;

ios/ReactNativePageView.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,18 @@ - (UIPageControl *)createPageIndicator:(UIView *)parentView {
279279

280280
#pragma mark - UIScrollViewDelegate
281281

282+
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
283+
_onPageScrollStateChanged(@{@"pageScrollState": @"dragging"});
284+
}
285+
286+
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
287+
_onPageScrollStateChanged(@{@"pageScrollState": @"settling"});
288+
}
289+
290+
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
291+
_onPageScrollStateChanged(@{@"pageScrollState": @"idle"});
292+
}
293+
282294
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
283295
CGPoint point = scrollView.contentOffset;
284296
float offset = (point.x - self.frame.size.width)/self.frame.size.width;

ios/ReactViewPagerManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ @implementation ReactViewPagerManager
1414
RCT_EXPORT_VIEW_PROPERTY(orientation, UIPageViewControllerNavigationOrientation)
1515
RCT_EXPORT_VIEW_PROPERTY(onPageSelected, RCTBubblingEventBlock)
1616
RCT_EXPORT_VIEW_PROPERTY(onPageScroll, RCTBubblingEventBlock)
17+
RCT_EXPORT_VIEW_PROPERTY(onPageScrollStateChanged, RCTBubblingEventBlock)
1718

1819
- (void) goToPage
1920
: (nonnull NSNumber *)reactTag index

0 commit comments

Comments
 (0)