Skip to content

Commit d1775a6

Browse files
authored
fix(ios): resolve scrollEnabled prop initialization timing issue (#1041)
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.
1 parent 12fc806 commit d1775a6

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

.github/workflows/ios.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ on:
1212
branches:
1313
- master
1414

15-
1615
jobs:
1716
ios-build:
1817
runs-on: macos-14
@@ -39,7 +38,7 @@ jobs:
3938
cache-name: cached-ios-pods-deps
4039
with:
4140
path: example/ios/Pods
42-
key: ${{ hashFiles('./example/ios/Podfile.lock') }}
41+
key: ${{ hashFiles('example/ios/Podfile.lock') }}
4342

4443
- name: Bundle app
4544
run: bun build:ios

example/bun.lockb

18.5 KB
Binary file not shown.

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ PODS:
13321332
- React-jsiexecutor
13331333
- React-RCTFBReactNativeSpec
13341334
- ReactCommon/turbomodule/core
1335-
- react-native-pager-view (6.8.1):
1335+
- react-native-pager-view (7.0.0):
13361336
- DoubleConversion
13371337
- glog
13381338
- hermes-engine
@@ -2321,7 +2321,7 @@ SPEC CHECKSUMS:
23212321
React-logger: 8edfcedc100544791cd82692ca5a574240a16219
23222322
React-Mapbuffer: c3f4b608e4a59dd2f6a416ef4d47a14400194468
23232323
React-microtasksnativemodule: 054f34e9b82f02bd40f09cebd4083828b5b2beb6
2324-
react-native-pager-view: 919534782a0489f7e2aeeb9a8b8959edfd3f067a
2324+
react-native-pager-view: 39dffe42e6c5d419a16e3b8fe6522e43abcdf7e3
23252325
react-native-safe-area-context: 562163222d999b79a51577eda2ea8ad2c32b4d06
23262326
React-NativeModulesApple: 2c4377e139522c3d73f5df582e4f051a838ff25e
23272327
React-oscompat: ef5df1c734f19b8003e149317d041b8ce1f7d29c

example/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"@babel/core": "^7.25.2",
3737
"@babel/preset-env": "^7.25.3",
3838
"@babel/runtime": "^7.25.0",
39-
"@react-native-community/cli": "17.0.1",
39+
"@react-native-community/cli": "15.0.1",
4040
"@react-native-community/cli-platform-android": "15.0.1",
4141
"@react-native-community/cli-platform-ios": "15.0.1",
4242
"@react-native/babel-preset": "0.79.2",
@@ -60,4 +60,4 @@
6060
"engines": {
6161
"node": ">=20"
6262
}
63-
}
63+
}

ios/RNCPagerViewComponentView.mm

Lines changed: 14 additions & 3 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,8 @@ - (void)initializeNativePageViewController {
6465
scrollView = (UIScrollView *)subview;
6566
}
6667
}
68+
69+
[self applyScrollEnabled];
6770
}
6871

6972
- (instancetype)initWithFrame:(CGRect)frame
@@ -76,6 +79,7 @@ - (instancetype)initWithFrame:(CGRect)frame
7679
_destinationIndex = -1;
7780
_layoutDirection = @"ltr";
7881
_overdrag = NO;
82+
_scrollEnabled = YES;
7983
}
8084

8185
return self;
@@ -126,6 +130,7 @@ -(void)prepareForRecycle {
126130
[super prepareForRecycle];
127131
_nativePageViewController = nil;
128132
_currentIndex = -1;
133+
_scrollEnabled = YES;
129134
}
130135

131136
- (void)shouldDismissKeyboard:(RNCViewPagerKeyboardDismissMode)dismissKeyboard {
@@ -143,6 +148,10 @@ - (void)shouldDismissKeyboard:(RNCViewPagerKeyboardDismissMode)dismissKeyboard {
143148
#endif
144149
}
145150

151+
- (void)applyScrollEnabled {
152+
scrollView.scrollEnabled = _scrollEnabled;
153+
}
154+
146155

147156
- (void)updateProps:(const facebook::react::Props::Shared &)props oldProps:(const facebook::react::Props::Shared &)oldProps{
148157
const auto &oldScreenProps = *std::static_pointer_cast<const RNCViewPagerProps>(_props);
@@ -165,8 +174,9 @@ - (void)updateProps:(const facebook::react::Props::Shared &)props oldProps:(cons
165174
[self shouldDismissKeyboard: newScreenProps.keyboardDismissMode];
166175
}
167176

168-
if (newScreenProps.scrollEnabled != scrollView.scrollEnabled) {
169-
scrollView.scrollEnabled = newScreenProps.scrollEnabled;
177+
if (oldScreenProps.scrollEnabled != newScreenProps.scrollEnabled) {
178+
_scrollEnabled = newScreenProps.scrollEnabled;
179+
[self applyScrollEnabled];
170180
}
171181

172182
if (newScreenProps.overdrag != _overdrag) {
@@ -387,7 +397,8 @@ - (void)setPageWithoutAnimation:(NSInteger)index {
387397
}
388398

389399
- (void)setScrollEnabledImperatively:(BOOL)scrollEnabled {
390-
[scrollView setScrollEnabled:scrollEnabled];
400+
_scrollEnabled = scrollEnabled;
401+
[self applyScrollEnabled];
391402
}
392403

393404
#pragma mark - Helpers

0 commit comments

Comments
 (0)