Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add visionOS support #2025

Merged
merged 6 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion RNScreens.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Pod::Spec.new do |s|
s.homepage = "https://github.com/software-mansion/react-native-screens"
s.license = "MIT"
s.author = { "author" => "author@domain.cn" }
s.platforms = { :ios => platform, :tvos => "11.0" }
s.platforms = { :ios => platform, :tvos => "11.0", :visionos => "1.0" }
s.source = { :git => "https://github.com/software-mansion/react-native-screens.git", :tag => "#{s.version}" }
s.source_files = source_files
s.requires_arc = true
Expand Down
2 changes: 2 additions & 0 deletions ios/RNSConvert.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ namespace react = facebook::react;
+ (NSDictionary *)gestureResponseDistanceDictFromCppStruct:
(const react::RNSScreenGestureResponseDistanceStruct &)gestureResponseDistance;

#if !TARGET_OS_VISION
+ (UITextAutocapitalizationType)UITextAutocapitalizationTypeFromCppEquivalent:
(react::RNSSearchBarAutoCapitalize)autoCapitalize;
#endif

+ (RNSSearchBarPlacement)RNSScreenSearchBarPlacementFromCppEquivalent:(react::RNSSearchBarPlacement)placement;

Expand Down
2 changes: 2 additions & 0 deletions ios/RNSConvert.mm
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ + (NSDictionary *)gestureResponseDistanceDictFromCppStruct:
};
}

#if !TARGET_OS_VISION
+ (UITextAutocapitalizationType)UITextAutocapitalizationTypeFromCppEquivalent:
(react::RNSSearchBarAutoCapitalize)autoCapitalize
{
Expand All @@ -137,6 +138,7 @@ + (UITextAutocapitalizationType)UITextAutocapitalizationTypeFromCppEquivalent:
return UITextAutocapitalizationTypeNone;
}
}
#endif

+ (RNSSearchBarPlacement)RNSScreenSearchBarPlacementFromCppEquivalent:(react::RNSSearchBarPlacement)placement
{
Expand Down
8 changes: 4 additions & 4 deletions ios/RNSScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ - (BOOL)isTransparentModal
self.controller.modalPresentationStyle == UIModalPresentationOverCurrentContext;
}

#if !TARGET_OS_TV
#if !TARGET_OS_TV && !TARGET_OS_VISION
/**
* Updates settings for sheet presentation controller.
* Note that this method should not be called inside `stackPresentation` setter, because on Paper we don't have
Expand Down Expand Up @@ -821,7 +821,7 @@ - (void)updateLayoutMetrics:(const react::LayoutMetrics &)layoutMetrics
- (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask
{
[super finalizeUpdates:updateMask];
#if !TARGET_OS_TV
#if !TARGET_OS_TV && !TARGET_OS_VISION
[self updatePresentationStyle];
#endif // !TARGET_OS_TV
}
Expand Down Expand Up @@ -1065,7 +1065,7 @@ - (BOOL)hasNestedStack

- (CGSize)getStatusBarHeightIsModal:(BOOL)isModal
{
#if !TARGET_OS_TV
#if !TARGET_OS_TV && !TARGET_OS_VISION
CGSize fallbackStatusBarSize = [[UIApplication sharedApplication] statusBarFrame].size;

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
Expand Down Expand Up @@ -1505,7 +1505,7 @@ @implementation RNSScreenManager
RCT_EXPORT_VIEW_PROPERTY(sheetExpandsWhenScrolledToEdge, BOOL);
#endif

#if !TARGET_OS_TV
#if !TARGET_OS_TV && !TARGET_OS_VISION
// See:
// 1. https://github.com/software-mansion/react-native-screens/pull/1543
// 2. https://github.com/software-mansion/react-native-screens/pull/1596
Expand Down
10 changes: 5 additions & 5 deletions ios/RNSScreenStack.mm
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ - (UIViewController *)childViewControllerForHomeIndicatorAutoHidden

@end

#if !TARGET_OS_TV
#if !TARGET_OS_TV && !TARGET_OS_VISION
@interface RNSScreenEdgeGestureRecognizer : UIScreenEdgePanGestureRecognizer
@end

Expand Down Expand Up @@ -150,7 +150,7 @@ - (void)initCommonProps
_presentedModals = [NSMutableArray new];
_controller = [RNSNavigationController new];
_controller.delegate = self;
#if !TARGET_OS_TV
#if !TARGET_OS_TV && !TARGET_OS_VISION
[self setupGestureHandlers];
#endif
// we have to initialize viewControllers with a non empty array for
Expand Down Expand Up @@ -731,7 +731,7 @@ - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
}
RNSScreenView *topScreen = _reactSubviews.lastObject;

#if TARGET_OS_TV
#if TARGET_OS_TV || TARGET_OS_VISION
[self cancelTouchesInParent];
return YES;
#else
Expand Down Expand Up @@ -774,7 +774,7 @@ - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
#endif // TARGET_OS_TV
}

#if !TARGET_OS_TV
#if !TARGET_OS_TV && !TARGET_OS_VISION
- (void)setupGestureHandlers
{
// gesture recognizers for custom stack animations
Expand Down Expand Up @@ -951,7 +951,7 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
return [super hitTest:point withEvent:event];
}

#if !TARGET_OS_TV
#if !TARGET_OS_TV && !TARGET_OS_VISION

- (BOOL)isScrollViewPanGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
{
Expand Down
8 changes: 5 additions & 3 deletions ios/RNSScreenWindowTraits.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ + (void)assertViewControllerBasedStatusBarAppearenceSet

+ (void)updateStatusBarAppearance
{
#if !TARGET_OS_TV
#if !TARGET_OS_TV && !TARGET_OS_VISION
[UIView animateWithDuration:0.4
animations:^{ // duration based on "Programming iOS 13" p. 311 implementation
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
Expand Down Expand Up @@ -56,7 +56,9 @@ + (void)updateHomeIndicatorAutoHidden
#endif
{
if (@available(iOS 11.0, *)) {
#if !TARGET_OS_VISION
[UIApplication.sharedApplication.keyWindow.rootViewController setNeedsUpdateOfHomeIndicatorAutoHidden];
okwasniewski marked this conversation as resolved.
Show resolved Hide resolved
#endif
}
}
#endif
Expand Down Expand Up @@ -134,7 +136,7 @@ + (UIInterfaceOrientationMask)maskFromOrientation:(UIInterfaceOrientation)orient

+ (void)enforceDesiredDeviceOrientation
{
#if !TARGET_OS_TV
#if !TARGET_OS_TV && !TARGET_OS_VISION
dispatch_async(dispatch_get_main_queue(), ^{
UIInterfaceOrientationMask orientationMask = UIInterfaceOrientationMaskAllButUpsideDown;
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
Expand Down Expand Up @@ -211,7 +213,7 @@ + (void)updateWindowTraits
[RNSScreenWindowTraits updateHomeIndicatorAutoHidden];
}

#if !TARGET_OS_TV
#if !TARGET_OS_TV && !TARGET_OS_VISION
// based on
// https://stackoverflow.com/questions/57965701/statusbarorientation-was-deprecated-in-ios-13-0-when-attempting-to-get-app-ori/61249908#61249908
+ (UIInterfaceOrientation)interfaceOrientation
Expand Down
2 changes: 2 additions & 0 deletions ios/RNSSearchBar.mm
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,11 @@ - (void)updateProps:(react::Props::Shared const &)props oldProps:(react::Props::
[self setPlaceholder:RCTNSStringFromStringNilIfEmpty(newScreenProps.placeholder)];
}

#if !TARGET_OS_VISION
if (oldScreenProps.autoCapitalize != newScreenProps.autoCapitalize) {
[self setAutoCapitalize:[RNSConvert UITextAutocapitalizationTypeFromCppEquivalent:newScreenProps.autoCapitalize]];
}
#endif

if (oldScreenProps.tintColor != newScreenProps.tintColor) {
[self setTintColor:RCTUIColorFromSharedColor(newScreenProps.tintColor)];
Expand Down
2 changes: 2 additions & 0 deletions ios/utils/RNSUIBarButtonItem.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#import <UIKit/UIKit.h>
okwasniewski marked this conversation as resolved.
Show resolved Hide resolved

@interface RNSUIBarButtonItem : UIBarButtonItem

@property (nonatomic) BOOL menuHidden;
Expand Down
Loading