Skip to content

Commit

Permalink
feat(ios): add support for visionOS (#797)
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski authored Dec 11, 2023
1 parent 7c30957 commit d0b77b3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ios/Fabric/RNCPagerViewComponentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ -(void)prepareForRecycle {
}

- (void)shouldDismissKeyboard:(RNCViewPagerKeyboardDismissMode)dismissKeyboard {
#if !TARGET_OS_VISION
UIScrollViewKeyboardDismissMode dismissKeyboardMode = UIScrollViewKeyboardDismissModeNone;
switch (dismissKeyboard) {
case RNCViewPagerKeyboardDismissMode::None:
Expand All @@ -132,6 +133,7 @@ - (void)shouldDismissKeyboard:(RNCViewPagerKeyboardDismissMode)dismissKeyboard {
break;
}
scrollView.keyboardDismissMode = dismissKeyboardMode;
#endif
}


Expand Down
2 changes: 2 additions & 0 deletions ios/ReactNativePageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic) NSInteger currentIndex;
@property(nonatomic) NSInteger pageMargin;
@property(nonatomic, readonly) BOOL scrollEnabled;
#if !TARGET_OS_VISION
@property(nonatomic, readonly) UIScrollViewKeyboardDismissMode dismissKeyboard;
#endif
@property(nonatomic) UIPageViewControllerNavigationOrientation orientation;
@property(nonatomic, copy) RCTDirectEventBlock onPageSelected;
@property(nonatomic, copy) RCTDirectEventBlock onPageScroll;
Expand Down
6 changes: 6 additions & 0 deletions ios/ReactNativePageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher {
_destinationIndex = -1;
_orientation = UIPageViewControllerNavigationOrientationHorizontal;
_currentIndex = 0;
#if !TARGET_OS_VISION
_dismissKeyboard = UIScrollViewKeyboardDismissModeNone;
#endif
_coalescingKey = 0;
_eventDispatcher = eventDispatcher;
_cachedControllers = [NSHashTable hashTableWithOptions:NSHashTableStrongMemory];
Expand Down Expand Up @@ -102,7 +104,9 @@ - (void)embed {
for (UIView *subview in pageViewController.view.subviews) {
if([subview isKindOfClass:UIScrollView.class]){
((UIScrollView *)subview).delegate = self;
#if !TARGET_OS_VISION
((UIScrollView *)subview).keyboardDismissMode = _dismissKeyboard;
#endif
((UIScrollView *)subview).delaysContentTouches = YES;
self.scrollView = (UIScrollView *)subview;
}
Expand All @@ -128,9 +132,11 @@ - (void)shouldScroll:(BOOL)scrollEnabled {
}

- (void)shouldDismissKeyboard:(NSString *)dismissKeyboard {
#if !TARGET_OS_VISION
_dismissKeyboard = [dismissKeyboard isEqual: @"on-drag"] ?
UIScrollViewKeyboardDismissModeOnDrag : UIScrollViewKeyboardDismissModeNone;
self.scrollView.keyboardDismissMode = _dismissKeyboard;
#endif
}

- (void)setupInitialController {
Expand Down
2 changes: 1 addition & 1 deletion react-native-pager-view.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Pod::Spec.new do |s|
s.license = package["license"]
s.authors = package["author"]

s.platforms = { :ios => "10.0" }
s.platforms = { :ios => "10.0", :visionos => "1.0" }
s.source = { :git => "https://github.com/callstack/react-native-pager-view.git", :tag => "#{s.version}" }

s.source_files = "ios/**/*.{h,m,mm}"
Expand Down

0 comments on commit d0b77b3

Please sign in to comment.