Skip to content

Commit 7cf8e41

Browse files
committed
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.
1 parent 12fc806 commit 7cf8e41

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

ios/RNCPagerViewComponentView.mm

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ @implementation RNCPagerViewComponentView {
2828
NSInteger _destinationIndex;
2929
BOOL _overdrag;
3030
NSString *_layoutDirection;
31+
BOOL _scrollEnabled;
3132
}
3233

3334
// Needed because of this: https://github.com/facebook/react-native/pull/37274
@@ -64,6 +65,9 @@ - (void)initializeNativePageViewController {
6465
scrollView = (UIScrollView *)subview;
6566
}
6667
}
68+
69+
// Apply scroll enabled state if it was set before initialization
70+
[self applyScrollEnabled];
6771
}
6872

6973
- (instancetype)initWithFrame:(CGRect)frame
@@ -76,6 +80,7 @@ - (instancetype)initWithFrame:(CGRect)frame
7680
_destinationIndex = -1;
7781
_layoutDirection = @"ltr";
7882
_overdrag = NO;
83+
_scrollEnabled = YES;
7984
}
8085

8186
return self;
@@ -143,6 +148,12 @@ - (void)shouldDismissKeyboard:(RNCViewPagerKeyboardDismissMode)dismissKeyboard {
143148
#endif
144149
}
145150

151+
- (void)applyScrollEnabled {
152+
if (scrollView != nil) {
153+
scrollView.scrollEnabled = _scrollEnabled;
154+
}
155+
}
156+
146157

147158
- (void)updateProps:(const facebook::react::Props::Shared &)props oldProps:(const facebook::react::Props::Shared &)oldProps{
148159
const auto &oldScreenProps = *std::static_pointer_cast<const RNCViewPagerProps>(_props);
@@ -165,8 +176,9 @@ - (void)updateProps:(const facebook::react::Props::Shared &)props oldProps:(cons
165176
[self shouldDismissKeyboard: newScreenProps.keyboardDismissMode];
166177
}
167178

168-
if (newScreenProps.scrollEnabled != scrollView.scrollEnabled) {
169-
scrollView.scrollEnabled = newScreenProps.scrollEnabled;
179+
if (newScreenProps.scrollEnabled != _scrollEnabled) {
180+
_scrollEnabled = newScreenProps.scrollEnabled;
181+
[self applyScrollEnabled];
170182
}
171183

172184
if (newScreenProps.overdrag != _overdrag) {

0 commit comments

Comments
 (0)