diff --git a/ios/RNCPagerViewComponentView.mm b/ios/RNCPagerViewComponentView.mm index ccc2595b..7d5c6cf1 100644 --- a/ios/RNCPagerViewComponentView.mm +++ b/ios/RNCPagerViewComponentView.mm @@ -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,9 @@ - (void)initializeNativePageViewController { scrollView = (UIScrollView *)subview; } } + + // Apply scroll enabled state if it was set before initialization + [self applyScrollEnabled]; } - (instancetype)initWithFrame:(CGRect)frame @@ -76,6 +80,7 @@ - (instancetype)initWithFrame:(CGRect)frame _destinationIndex = -1; _layoutDirection = @"ltr"; _overdrag = NO; + _scrollEnabled = YES; } return self; @@ -126,6 +131,7 @@ -(void)prepareForRecycle { [super prepareForRecycle]; _nativePageViewController = nil; _currentIndex = -1; + _scrollEnabled = YES; } - (void)shouldDismissKeyboard:(RNCViewPagerKeyboardDismissMode)dismissKeyboard { @@ -143,6 +149,12 @@ - (void)shouldDismissKeyboard:(RNCViewPagerKeyboardDismissMode)dismissKeyboard { #endif } +- (void)applyScrollEnabled { + if (scrollView != nil) { + 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(_props); @@ -165,8 +177,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 +400,8 @@ - (void)setPageWithoutAnimation:(NSInteger)index { } - (void)setScrollEnabledImperatively:(BOOL)scrollEnabled { - [scrollView setScrollEnabled:scrollEnabled]; + _scrollEnabled = scrollEnabled; + [self applyScrollEnabled]; } #pragma mark - Helpers