From db0029e52d48fcef4e9fd69e03f902f7ece4d094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwas=CC=81niewski?= Date: Sat, 22 Nov 2025 20:22:27 +0100 Subject: [PATCH] fix(ios): resolve scrollEnabled prop initialization timing issue Store scrollEnabled state in an ivar and apply it when the scroll view becomes available, rather than attempting to set it before initialization. This ensures the prop works reliably regardless of when props are updated relative to UIPageViewController setup. Also reset scrollEnabled to its default value (YES) in prepareForRecycle to prevent recycled components from retaining the previous instance's scroll state. Update setScrollEnabledImperatively to use the new state management pattern by updating the ivar and calling applyScrollEnabled, ensuring consistency whether called before or after scrollView initialization. --- ios/RNCPagerViewComponentView.mm | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) 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