Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions ios/RNCPagerViewComponentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -76,6 +80,7 @@ - (instancetype)initWithFrame:(CGRect)frame
_destinationIndex = -1;
_layoutDirection = @"ltr";
_overdrag = NO;
_scrollEnabled = YES;
}

return self;
Expand Down Expand Up @@ -126,6 +131,7 @@ -(void)prepareForRecycle {
[super prepareForRecycle];
_nativePageViewController = nil;
_currentIndex = -1;
_scrollEnabled = YES;
}

- (void)shouldDismissKeyboard:(RNCViewPagerKeyboardDismissMode)dismissKeyboard {
Expand All @@ -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<const RNCViewPagerProps>(_props);
Expand All @@ -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) {
Expand Down Expand Up @@ -387,7 +400,8 @@ - (void)setPageWithoutAnimation:(NSInteger)index {
}

- (void)setScrollEnabledImperatively:(BOOL)scrollEnabled {
[scrollView setScrollEnabled:scrollEnabled];
_scrollEnabled = scrollEnabled;
[self applyScrollEnabled];
}

#pragma mark - Helpers
Expand Down
Loading