Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ios/Fabric/RNCPagerViewComponentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic) NSInteger destinationIndex;
@property(nonatomic) NSString* layoutDirection;
@property(nonatomic) BOOL overdrag;
@property(nonatomic) BOOL isDragging;

- (void)setPage:(NSInteger)number;
- (void)setPageWithoutAnimation:(NSInteger)number;
Expand Down
24 changes: 24 additions & 0 deletions ios/Fabric/RNCPagerViewComponentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ - (instancetype)initWithFrame:(CGRect)frame
_destinationIndex = -1;
_layoutDirection = @"ltr";
_overdrag = NO;
_isDragging = NO;
}

return self;
Expand All @@ -83,6 +84,27 @@ - (void)willMoveToSuperview:(UIView *)newSuperview {
}
}

-(void) didMoveToWindow {
UIPanGestureRecognizer* gesture = [UIPanGestureRecognizer new];
gesture.delegate = self;
[self addGestureRecognizer: gesture];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
if (otherGestureRecognizer == self->scrollView.panGestureRecognizer) {
UIPanGestureRecognizer* p = (UIPanGestureRecognizer*) gestureRecognizer;
CGPoint velocity = [p velocityInView:self];
if (!_isDragging && self.currentIndex == 0 && velocity.x > 0) {
self->scrollView.panGestureRecognizer.enabled = false;
return NO;
} else {
self->scrollView.panGestureRecognizer.enabled = self->scrollView.scrollEnabled;
}
} else {
self->scrollView.panGestureRecognizer.enabled = self->scrollView.scrollEnabled;
}
return YES;
}

#pragma mark - React API

Expand Down Expand Up @@ -270,6 +292,7 @@ - (UIViewController *)currentlyDisplayed {
#pragma mark - UIScrollViewDelegate

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
_isDragging = YES;
const auto strongEventEmitter = *std::dynamic_pointer_cast<const RNCViewPagerEventEmitter>(_eventEmitter);
strongEventEmitter.onPageScrollStateChanged(RNCViewPagerEventEmitter::OnPageScrollStateChanged{.pageScrollState = RNCViewPagerEventEmitter::OnPageScrollStateChangedPageScrollState::Dragging });
}
Expand Down Expand Up @@ -298,6 +321,7 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
_isDragging = NO;
const auto strongEventEmitter = *std::dynamic_pointer_cast<const RNCViewPagerEventEmitter>(_eventEmitter);
strongEventEmitter.onPageScrollStateChanged(RNCViewPagerEventEmitter::OnPageScrollStateChanged{.pageScrollState = RNCViewPagerEventEmitter::OnPageScrollStateChangedPageScrollState::Idle });
}
Expand Down