Skip to content

Commit 5e3bb6b

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. Also reset scrollEnabled to its default value (YES) in prepareForRecycle to prevent recycled components from retaining the previous instance's scroll state.
1 parent 12fc806 commit 5e3bb6b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

ios/RNCPagerViewComponentView.mm

Lines changed: 15 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;
@@ -126,6 +131,7 @@ -(void)prepareForRecycle {
126131
[super prepareForRecycle];
127132
_nativePageViewController = nil;
128133
_currentIndex = -1;
134+
_scrollEnabled = YES;
129135
}
130136

131137
- (void)shouldDismissKeyboard:(RNCViewPagerKeyboardDismissMode)dismissKeyboard {
@@ -143,6 +149,12 @@ - (void)shouldDismissKeyboard:(RNCViewPagerKeyboardDismissMode)dismissKeyboard {
143149
#endif
144150
}
145151

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

147159
- (void)updateProps:(const facebook::react::Props::Shared &)props oldProps:(const facebook::react::Props::Shared &)oldProps{
148160
const auto &oldScreenProps = *std::static_pointer_cast<const RNCViewPagerProps>(_props);
@@ -165,8 +177,9 @@ - (void)updateProps:(const facebook::react::Props::Shared &)props oldProps:(cons
165177
[self shouldDismissKeyboard: newScreenProps.keyboardDismissMode];
166178
}
167179

168-
if (newScreenProps.scrollEnabled != scrollView.scrollEnabled) {
169-
scrollView.scrollEnabled = newScreenProps.scrollEnabled;
180+
if (oldScreenProps.scrollEnabled != newScreenProps.scrollEnabled) {
181+
_scrollEnabled = newScreenProps.scrollEnabled;
182+
[self applyScrollEnabled];
170183
}
171184

172185
if (newScreenProps.overdrag != _overdrag) {

0 commit comments

Comments
 (0)