-
Notifications
You must be signed in to change notification settings - Fork 465
Fix: Navigation gesture gestureResponseDistance failure #1016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
83964f1
ee3acd5
945ff5a
8f06486
0094584
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ | |
|
|
||
| using namespace facebook::react; | ||
|
|
||
| @interface RNCPagerViewComponentView () <RCTRNCViewPagerViewProtocol, UIPageViewControllerDataSource, UIPageViewControllerDelegate, UIScrollViewDelegate> | ||
| @interface RNCPagerViewComponentView () <RCTRNCViewPagerViewProtocol, UIPageViewControllerDataSource, UIPageViewControllerDelegate, UIScrollViewDelegate, UIGestureRecognizerDelegate> | ||
|
|
||
| @property(nonatomic, strong) UIPageViewController *nativePageViewController; | ||
| @property(nonatomic, strong) NSMutableArray<UIViewController *> *nativeChildrenViewControllers; | ||
|
|
@@ -28,6 +28,9 @@ @implementation RNCPagerViewComponentView { | |
| NSInteger _destinationIndex; | ||
| BOOL _overdrag; | ||
| NSString *_layoutDirection; | ||
| BOOL _isDragging; | ||
| BOOL _allowNavFullscreenGesture; | ||
| UIPanGestureRecognizer *_navGestureRecognizer; | ||
| } | ||
|
|
||
| // Needed because of this: https://github.com/facebook/react-native/pull/37274 | ||
|
|
@@ -76,6 +79,9 @@ - (instancetype)initWithFrame:(CGRect)frame | |
| _destinationIndex = -1; | ||
| _layoutDirection = @"ltr"; | ||
| _overdrag = NO; | ||
| _isDragging = NO; | ||
| _allowNavFullscreenGesture = NO; | ||
|
kazhoang marked this conversation as resolved.
Outdated
|
||
| _navGestureRecognizer = nil; | ||
| } | ||
|
|
||
| return self; | ||
|
|
@@ -88,6 +94,27 @@ - (void)willMoveToSuperview:(UIView *)newSuperview { | |
| } | ||
| } | ||
|
|
||
| - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { | ||
|
kazhoang marked this conversation as resolved.
|
||
| if (!_allowNavFullscreenGesture) { | ||
| return NO; | ||
| } | ||
|
|
||
| if (otherGestureRecognizer == self->scrollView.panGestureRecognizer) { | ||
| UIPanGestureRecognizer* p = (UIPanGestureRecognizer*) gestureRecognizer; | ||
| CGPoint velocity = [p velocityInView:self]; | ||
|
kazhoang marked this conversation as resolved.
Outdated
|
||
| BOOL shouldPagerGestureFail = !_overdrag && !_isDragging && _currentIndex == 0 && velocity.x > 0; | ||
|
troZee marked this conversation as resolved.
Outdated
|
||
| if (shouldPagerGestureFail) { | ||
| self->scrollView.panGestureRecognizer.enabled = false; | ||
|
troZee marked this conversation as resolved.
Outdated
troZee marked this conversation as resolved.
Outdated
|
||
| return NO; | ||
| } else { | ||
| self->scrollView.panGestureRecognizer.enabled = self->scrollView.scrollEnabled; | ||
| } | ||
| } else { | ||
| self->scrollView.panGestureRecognizer.enabled = self->scrollView.scrollEnabled; | ||
| } | ||
|
|
||
| return YES; | ||
| } | ||
|
|
||
| #pragma mark - React API | ||
|
|
||
|
|
@@ -126,6 +153,11 @@ -(void)prepareForRecycle { | |
| [super prepareForRecycle]; | ||
| _nativePageViewController = nil; | ||
| _currentIndex = -1; | ||
| _allowNavFullscreenGesture = NO; | ||
| if (_navGestureRecognizer) { | ||
| [self removeGestureRecognizer:_navGestureRecognizer]; | ||
| _navGestureRecognizer = nil; | ||
| } | ||
| } | ||
|
|
||
| - (void)shouldDismissKeyboard:(RNCViewPagerKeyboardDismissMode)dismissKeyboard { | ||
|
|
@@ -173,6 +205,22 @@ - (void)updateProps:(const facebook::react::Props::Shared &)props oldProps:(cons | |
| _overdrag = newScreenProps.overdrag; | ||
| } | ||
|
|
||
| if (newScreenProps.allowNavFullscreenGesture != _allowNavFullscreenGesture) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should check previous screen properties in here. Same as other props |
||
| _allowNavFullscreenGesture = newScreenProps.allowNavFullscreenGesture; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we also don't need to store this as it's stored in
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @okwasniewski
|
||
|
|
||
| if (_allowNavFullscreenGesture) { | ||
| _navGestureRecognizer = [[UIPanGestureRecognizer alloc] init]; | ||
|
troZee marked this conversation as resolved.
|
||
| _navGestureRecognizer.delegate = self; | ||
| [self addGestureRecognizer:_navGestureRecognizer]; | ||
| _isDragging = NO; | ||
| } else { | ||
| if (_navGestureRecognizer) { | ||
| [self removeGestureRecognizer:_navGestureRecognizer]; | ||
| _navGestureRecognizer = nil; | ||
|
kazhoang marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| [super updateProps:props oldProps:oldProps]; | ||
| } | ||
|
|
||
|
|
@@ -264,6 +312,7 @@ - (UIViewController *)currentlyDisplayed { | |
| #pragma mark - UIScrollViewDelegate | ||
|
|
||
| - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { | ||
| _isDragging = YES; | ||
| const auto eventEmitter = [self pagerEventEmitter]; | ||
| eventEmitter->onPageScrollStateChanged(RNCViewPagerEventEmitter::OnPageScrollStateChanged{.pageScrollState = RNCViewPagerEventEmitter::OnPageScrollStateChangedPageScrollState::Dragging }); | ||
| } | ||
|
|
@@ -290,6 +339,7 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi | |
| } | ||
|
|
||
| - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { | ||
| _isDragging = NO; | ||
|
kazhoang marked this conversation as resolved.
Outdated
|
||
| const auto eventEmitter = [self pagerEventEmitter]; | ||
| eventEmitter->onPageScrollStateChanged(RNCViewPagerEventEmitter::OnPageScrollStateChanged{.pageScrollState = RNCViewPagerEventEmitter::OnPageScrollStateChangedPageScrollState::Idle }); | ||
| } | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.