diff --git a/packages/react-native/React/Base/RCTConvert.h b/packages/react-native/React/Base/RCTConvert.h index ecec4e24fde4..85b2b7239488 100644 --- a/packages/react-native/React/Base/RCTConvert.h +++ b/packages/react-native/React/Base/RCTConvert.h @@ -79,7 +79,9 @@ typedef NSURL RCTFileURL; + (UIKeyboardAppearance)UIKeyboardAppearance:(id)json; + (UIReturnKeyType)UIReturnKeyType:(id)json; + (UIUserInterfaceStyle)UIUserInterfaceStyle:(id)json API_AVAILABLE(ios(12)); +#if !TARGET_OS_TV + (UIInterfaceOrientationMask)UIInterfaceOrientationMask:(NSString *)orientation; +#endif + (UIModalPresentationStyle)UIModalPresentationStyle:(id)json; #if !TARGET_OS_TV diff --git a/packages/react-native/React/Base/RCTConvert.mm b/packages/react-native/React/Base/RCTConvert.mm index f549b0d0bfda..0194bfa66950 100644 --- a/packages/react-native/React/Base/RCTConvert.mm +++ b/packages/react-native/React/Base/RCTConvert.mm @@ -499,6 +499,7 @@ + (UIKeyboardType)UIKeyboardType:(id)json RCT_DYNAMIC UIUserInterfaceStyleUnspecified, integerValue) +#if !TARGET_OS_TV RCT_ENUM_CONVERTER( UIInterfaceOrientationMask, (@{ @@ -510,6 +511,7 @@ + (UIKeyboardType)UIKeyboardType:(id)json RCT_DYNAMIC }), NSNotFound, unsignedIntegerValue) +#endif RCT_ENUM_CONVERTER( UIModalPresentationStyle, diff --git a/packages/react-native/React/Base/RCTUtils.h b/packages/react-native/React/Base/RCTUtils.h index 6fa772038ef8..aaa0bd237d90 100644 --- a/packages/react-native/React/Base/RCTUtils.h +++ b/packages/react-native/React/Base/RCTUtils.h @@ -101,7 +101,9 @@ RCT_EXTERN UIWindow *__nullable RCTKeyWindow(void); RCT_EXTERN UIViewController *__nullable RCTPresentedViewController(void); // Retrieve current window UIStatusBarManager +#if !TARGET_OS_TV RCT_EXTERN UIStatusBarManager *__nullable RCTUIStatusBarManager(void) API_AVAILABLE(ios(13)); +#endif // Does this device support force touch (aka 3D Touch)? RCT_EXTERN BOOL RCTForceTouchAvailable(void); diff --git a/packages/react-native/React/Base/RCTUtils.mm b/packages/react-native/React/Base/RCTUtils.mm index 20503a564dfb..e6f8aa1062bb 100644 --- a/packages/react-native/React/Base/RCTUtils.mm +++ b/packages/react-native/React/Base/RCTUtils.mm @@ -635,10 +635,12 @@ BOOL RCTRunningInAppExtension(void) return nil; } +#if !TARGET_OS_TV UIStatusBarManager *__nullable RCTUIStatusBarManager(void) { return RCTKeyWindow().windowScene.statusBarManager; } +#endif UIViewController *__nullable RCTPresentedViewController(void) { diff --git a/packages/react-native/React/Views/RCTModalHostView.h b/packages/react-native/React/Views/RCTModalHostView.h index a193cc31386c..ca2a97aa7e9b 100644 --- a/packages/react-native/React/Views/RCTModalHostView.h +++ b/packages/react-native/React/Views/RCTModalHostView.h @@ -38,8 +38,10 @@ __attribute__((deprecated("This API will be removed along with the legacy archit @property (nonatomic, weak) id delegate; +#if !TARGET_OS_TV @property (nonatomic, copy) NSArray *supportedOrientations; @property (nonatomic, copy) RCTDirectEventBlock onOrientationChange; +#endif // Fabric only @property (nonatomic, copy) RCTDirectEventBlock onDismiss; diff --git a/packages/react-native/React/Views/RCTModalHostView.m b/packages/react-native/React/Views/RCTModalHostView.m index d8705f0c3f78..3b577704b8be 100644 --- a/packages/react-native/React/Views/RCTModalHostView.m +++ b/packages/react-native/React/Views/RCTModalHostView.m @@ -25,7 +25,9 @@ @implementation RCTModalHostView { RCTModalHostViewController *_modalViewController; RCTTouchHandler *_touchHandler; UIView *_reactSubview; +#if !TARGET_OS_TV UIInterfaceOrientation _lastKnownOrientation; +#endif RCTDirectEventBlock _onRequestClose; } @@ -90,6 +92,7 @@ - (void)presentationControllerDidDismiss:(UIPresentationController *)presentatio - (void)notifyForOrientationChange { +#if !TARGET_OS_TV if (!_onOrientationChange) { return; } @@ -106,6 +109,7 @@ - (void)notifyForOrientationChange @"orientation" : isPortrait ? @"portrait" : @"landscape", }; _onOrientationChange(eventPayload); +#endif } - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex @@ -191,7 +195,9 @@ - (void)ensurePresentedOnlyIfNeeded if (shouldBePresented) { RCTAssert(self.reactViewController, @"Can't present modal view controller without a presenting view controller"); +#if !TARGET_OS_TV _modalViewController.supportedInterfaceOrientations = [self supportedOrientationsMask]; +#endif if ([self.animationType isEqualToString:@"fade"]) { _modalViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; @@ -224,6 +230,7 @@ - (void)setTransparent:(BOOL)transparent transparent ? UIModalPresentationOverFullScreen : UIModalPresentationFullScreen; } +#if !TARGET_OS_TV - (UIInterfaceOrientationMask)supportedOrientationsMask { if (_supportedOrientations.count == 0) { @@ -250,6 +257,7 @@ - (UIInterfaceOrientationMask)supportedOrientationsMask } return supportedOrientations; } +#endif @end diff --git a/packages/react-native/React/Views/RCTModalHostViewController.h b/packages/react-native/React/Views/RCTModalHostViewController.h index 53502ab8fbd5..80b075045e5f 100644 --- a/packages/react-native/React/Views/RCTModalHostViewController.h +++ b/packages/react-native/React/Views/RCTModalHostViewController.h @@ -14,7 +14,9 @@ __attribute__((deprecated("This API will be removed along with the legacy archit @property (nonatomic, copy) void (^boundsDidChangeBlock)(CGRect newBounds); +#if !TARGET_OS_TV @property (nonatomic, assign) UIInterfaceOrientationMask supportedInterfaceOrientations; +#endif @end diff --git a/packages/react-native/React/Views/ScrollView/RCTScrollView.h b/packages/react-native/React/Views/ScrollView/RCTScrollView.h index 2aa0f7989ee2..e3167c3fa828 100644 --- a/packages/react-native/React/Views/ScrollView/RCTScrollView.h +++ b/packages/react-native/React/Views/ScrollView/RCTScrollView.h @@ -51,10 +51,12 @@ __attribute__((deprecated("This API will be removed along with the legacy archit @property (nonatomic, assign) BOOL snapToEnd; @property (nonatomic, copy) NSString *snapToAlignment; @property (nonatomic, assign) BOOL inverted; +#if !TARGET_OS_TV /** Focus area of newly-activated text input relative to the window to compare against UIKeyboardFrameBegin/End */ @property (nonatomic, assign) CGRect firstResponderFocus; /** newly-activated text input outside of the scroll view */ @property (nonatomic, weak) UIView *firstResponderViewOutsideScrollView; +#endif // NOTE: currently these event props are only declared so we can export the // event names to JS - we don't call the blocks directly because scroll events diff --git a/packages/react-native/React/Views/ScrollView/RCTScrollView.m b/packages/react-native/React/Views/ScrollView/RCTScrollView.m index 72c7c39e3c1a..7edbc8ca6b42 100644 --- a/packages/react-native/React/Views/ScrollView/RCTScrollView.m +++ b/packages/react-native/React/Views/ScrollView/RCTScrollView.m @@ -211,16 +211,22 @@ - (void)setCustomRefreshControl:(UIView *)refre if ([_customRefreshControl respondsToSelector:@selector(setScrollView:)]) { _customRefreshControl.scrollView = self; } +#if !TARGET_OS_TV if ([refreshControl isKindOfClass:UIRefreshControl.class]) { self.refreshControl = (UIRefreshControl *)refreshControl; } else { +#endif [self addSubview:_customRefreshControl]; +#if !TARGET_OS_TV } +#endif } - (void)setPinchGestureEnabled:(BOOL)pinchGestureEnabled { +#if !TARGET_OS_TV self.pinchGestureRecognizer.enabled = pinchGestureEnabled; +#endif _pinchGestureEnabled = pinchGestureEnabled; } @@ -229,7 +235,9 @@ - (void)didMoveToWindow [super didMoveToWindow]; // ScrollView enables pinch gesture late in its lifecycle. So simply setting it // in the setter gets overridden when the view loads. +#if !TARGET_OS_TV self.pinchGestureRecognizer.enabled = _pinchGestureEnabled; +#endif } - (BOOL)shouldGroupAccessibilityChildren @@ -260,15 +268,19 @@ @implementation RCTScrollView { - (void)_registerKeyboardListener { +#if !TARGET_OS_TV [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil]; +#endif } - (void)_unregisterKeyboardListener { +#if !TARGET_OS_TV [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil]; +#endif } static inline UIViewAnimationOptions animationOptionsWithCurve(UIViewAnimationCurve curve) @@ -283,6 +295,7 @@ static inline UIViewAnimationOptions animationOptionsWithCurve(UIViewAnimationCu - (void)_keyboardWillChangeFrame:(NSNotification *)notification { +#if !TARGET_OS_TV if (![self automaticallyAdjustKeyboardInsets]) { return; } @@ -358,6 +371,7 @@ - (void)_keyboardWillChangeFrame:(NSNotification *)notification [self scrollToOffset:newContentOffset animated:NO]; } completion:nil]; +#endif } - (instancetype)initWithEventDispatcher:(id)eventDispatcher @@ -428,7 +442,11 @@ - (void)insertReactSubview:(UIView *)view atIndex:(NSInteger)atIndex [super insertReactSubview:view atIndex:atIndex]; if ([view conformsToProtocol:@protocol(RCTCustomRefreshControlProtocol)]) { [_scrollView setCustomRefreshControl:(UIView *)view]; +#if !TARGET_OS_TV if (![view isKindOfClass:[UIRefreshControl class]] && [view conformsToProtocol:@protocol(UIScrollViewDelegate)]) { +#else + if ([view conformsToProtocol:@protocol(UIScrollViewDelegate)]) { +#endif [self addScrollListener:(UIView *)view]; } } else { @@ -449,8 +467,12 @@ - (void)removeReactSubview:(UIView *)subview [super removeReactSubview:subview]; if ([subview conformsToProtocol:@protocol(RCTCustomRefreshControlProtocol)]) { [_scrollView setCustomRefreshControl:nil]; +#if !TARGET_OS_TV if (![subview isKindOfClass:[UIRefreshControl class]] && [subview conformsToProtocol:@protocol(UIScrollViewDelegate)]) { +#else + if ([subview conformsToProtocol:@protocol(UIScrollViewDelegate)]) { +#endif [self removeScrollListener:(UIView *)subview]; } } else { @@ -1083,8 +1105,10 @@ -(type)getter \ RCT_SET_AND_PRESERVE_OFFSET(setMaximumZoomScale, maximumZoomScale, CGFloat) RCT_SET_AND_PRESERVE_OFFSET(setMinimumZoomScale, minimumZoomScale, CGFloat) RCT_SET_AND_PRESERVE_OFFSET(setScrollEnabled, isScrollEnabled, BOOL) +#if !TARGET_OS_TV RCT_SET_AND_PRESERVE_OFFSET(setPagingEnabled, isPagingEnabled, BOOL) RCT_SET_AND_PRESERVE_OFFSET(setScrollsToTop, scrollsToTop, BOOL) +#endif RCT_SET_AND_PRESERVE_OFFSET(setShowsHorizontalScrollIndicator, showsHorizontalScrollIndicator, BOOL) RCT_SET_AND_PRESERVE_OFFSET(setShowsVerticalScrollIndicator, showsVerticalScrollIndicator, BOOL) RCT_SET_AND_PRESERVE_OFFSET(setZoomScale, zoomScale, CGFloat);