-
Notifications
You must be signed in to change notification settings - Fork 454
fix(ios): resolve scrollEnabled prop initialization timing issue #1041
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ @implementation RNCPagerViewComponentView { | |
| NSInteger _destinationIndex; | ||
| BOOL _overdrag; | ||
| NSString *_layoutDirection; | ||
| BOOL _scrollEnabled; | ||
| } | ||
|
|
||
| // Needed because of this: https://github.com/facebook/react-native/pull/37274 | ||
|
|
@@ -64,6 +65,8 @@ - (void)initializeNativePageViewController { | |
| scrollView = (UIScrollView *)subview; | ||
| } | ||
| } | ||
|
|
||
| [self applyScrollEnabled]; | ||
| } | ||
|
|
||
| - (instancetype)initWithFrame:(CGRect)frame | ||
|
|
@@ -76,6 +79,7 @@ - (instancetype)initWithFrame:(CGRect)frame | |
| _destinationIndex = -1; | ||
| _layoutDirection = @"ltr"; | ||
| _overdrag = NO; | ||
| _scrollEnabled = YES; | ||
|
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. When adapting this code to patch version 6.9.1 in our app I had to remove this line to make it work. Don't know if you need to do the same in this PR but just wanted to share my findings and give you a heads up. Thank you for fixing this!
Member
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. Thanks for checking it out! I'm not sure why it wouldn't work for you.. Without setting this to YES the state will be desynchronized (as the default for a scroll view is to have scroll enabled). I did some additional tests and it was working well with this. |
||
| } | ||
|
|
||
| return self; | ||
|
|
@@ -126,6 +130,7 @@ -(void)prepareForRecycle { | |
| [super prepareForRecycle]; | ||
| _nativePageViewController = nil; | ||
| _currentIndex = -1; | ||
| _scrollEnabled = YES; | ||
okwasniewski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| - (void)shouldDismissKeyboard:(RNCViewPagerKeyboardDismissMode)dismissKeyboard { | ||
|
|
@@ -143,6 +148,10 @@ - (void)shouldDismissKeyboard:(RNCViewPagerKeyboardDismissMode)dismissKeyboard { | |
| #endif | ||
| } | ||
|
|
||
| - (void)applyScrollEnabled { | ||
okwasniewski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| scrollView.scrollEnabled = _scrollEnabled; | ||
| } | ||
|
|
||
|
|
||
| - (void)updateProps:(const facebook::react::Props::Shared &)props oldProps:(const facebook::react::Props::Shared &)oldProps{ | ||
| const auto &oldScreenProps = *std::static_pointer_cast<const RNCViewPagerProps>(_props); | ||
|
|
@@ -165,8 +174,9 @@ - (void)updateProps:(const facebook::react::Props::Shared &)props oldProps:(cons | |
| [self shouldDismissKeyboard: newScreenProps.keyboardDismissMode]; | ||
| } | ||
|
|
||
| if (newScreenProps.scrollEnabled != scrollView.scrollEnabled) { | ||
| scrollView.scrollEnabled = newScreenProps.scrollEnabled; | ||
| if (oldScreenProps.scrollEnabled != newScreenProps.scrollEnabled) { | ||
| _scrollEnabled = newScreenProps.scrollEnabled; | ||
| [self applyScrollEnabled]; | ||
| } | ||
|
|
||
| if (newScreenProps.overdrag != _overdrag) { | ||
|
|
@@ -387,7 +397,8 @@ - (void)setPageWithoutAnimation:(NSInteger)index { | |
| } | ||
|
|
||
| - (void)setScrollEnabledImperatively:(BOOL)scrollEnabled { | ||
| [scrollView setScrollEnabled:scrollEnabled]; | ||
| _scrollEnabled = scrollEnabled; | ||
| [self applyScrollEnabled]; | ||
| } | ||
|
|
||
| #pragma mark - Helpers | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.