From 87d3a197359bea5920281c29e8ef8cc8e15d3a85 Mon Sep 17 00:00:00 2001 From: Devan Buggay Date: Fri, 16 Jan 2026 13:54:04 -0800 Subject: [PATCH] Compile out more unsupported UIKit APIs (#55213) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55213 Compiling out some various unsupported UIKit APIs. Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D90825451 fbshipit-source-id: ee88cc3937c5e17540a2951b39a354f297dd3c41 --- packages/react-native/React/Base/RCTUtils.mm | 12 +++++++++--- .../React/CoreModules/RCTDeviceInfo.mm | 2 +- .../React/CoreModules/RCTPerfMonitor.mm | 4 ++++ .../ScrollView/RCTScrollViewComponentView.mm | 2 ++ .../Text/RCTParagraphComponentView.mm | 15 +++++++++++++++ .../ComponentViews/View/RCTViewComponentView.mm | 7 ++++++- .../React/Modules/RCTLayoutAnimation.m | 10 ++++++++++ packages/react-native/React/Profiler/RCTProfile.m | 4 ++++ 8 files changed, 51 insertions(+), 5 deletions(-) diff --git a/packages/react-native/React/Base/RCTUtils.mm b/packages/react-native/React/Base/RCTUtils.mm index ac3136e10b5..ba4e930c731 100644 --- a/packages/react-native/React/Base/RCTUtils.mm +++ b/packages/react-native/React/Base/RCTUtils.mm @@ -311,10 +311,12 @@ void RCTUnsafeExecuteOnMainQueueSync(dispatch_block_t block) return; } +#if !TARGET_OS_TV if (ReactNativeFeatureFlags::enableMainQueueCoordinatorOnIOS()) { unsafeExecuteOnMainThreadSync(block); return; } +#endif dispatch_sync(dispatch_get_main_queue(), ^{ block(); @@ -339,10 +341,12 @@ static void RCTUnsafeExecuteOnMainQueueOnceSync(dispatch_once_t *onceToken, disp return; } +#if !TARGET_OS_TV if (ReactNativeFeatureFlags::enableMainQueueCoordinatorOnIOS()) { unsafeExecuteOnMainThreadSync(block); return; } +#endif dispatch_sync(dispatch_get_main_queue(), executeOnce); } @@ -421,10 +425,9 @@ CGSize RCTViewportSize(void) CGSize RCTSwitchSize(void) { - // UISwitch is not supported on AppleTV #if TARGET_OS_TV return CGSizeMake(0, 0); -#endif +#else static CGSize rctSwitchSize; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ @@ -433,6 +436,7 @@ CGSize RCTSwitchSize(void) }); }); return rctSwitchSize; +#endif } CGFloat RCTRoundPixelValue(CGFloat value) @@ -642,7 +646,9 @@ UIWindow *__nullable RCTKeyWindow(void) // We have apps internally that might use UIScenes which are not window scenes. // Calling keyWindow on a UIScene which is not a UIWindowScene can cause a crash UIWindowScene *windowScene = (UIWindowScene *)sceneToUse; - return windowScene.keyWindow; + if (@available(iOS 15.0, tvOS 15.0, *)) { + return windowScene.keyWindow; + } } return nil; diff --git a/packages/react-native/React/CoreModules/RCTDeviceInfo.mm b/packages/react-native/React/CoreModules/RCTDeviceInfo.mm index c5946382d08..40b0adf9348 100644 --- a/packages/react-native/React/CoreModules/RCTDeviceInfo.mm +++ b/packages/react-native/React/CoreModules/RCTDeviceInfo.mm @@ -166,9 +166,9 @@ RCT_EXPORT_MODULE() static BOOL RCTIsIPhoneNotched() { static BOOL isIPhoneNotched = NO; - static dispatch_once_t onceToken; #if TARGET_OS_IOS + static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ RCTAssertMainQueue(); diff --git a/packages/react-native/React/CoreModules/RCTPerfMonitor.mm b/packages/react-native/React/CoreModules/RCTPerfMonitor.mm index e67ef6a4076..3195fdaffb0 100644 --- a/packages/react-native/React/CoreModules/RCTPerfMonitor.mm +++ b/packages/react-native/React/CoreModules/RCTPerfMonitor.mm @@ -180,7 +180,11 @@ RCT_EXPORT_MODULE() [_container addGestureRecognizer:self.gestureRecognizer]; [_container addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)]]; +#if TARGET_OS_TV + _container.backgroundColor = [UIColor whiteColor]; +#else _container.backgroundColor = [UIColor systemBackgroundColor]; +#endif } return _container; diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm index 15e75f45632..03d3b23c64c 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm @@ -352,9 +352,11 @@ static inline UIViewAnimationOptions animationOptionsWithCurve(UIViewAnimationCu MAP_SCROLL_VIEW_PROP(maximumZoomScale); MAP_SCROLL_VIEW_PROP(minimumZoomScale); MAP_SCROLL_VIEW_PROP(scrollEnabled); +#if !TARGET_OS_TV MAP_SCROLL_VIEW_PROP(pagingEnabled); MAP_SCROLL_VIEW_PROP(pinchGestureEnabled); MAP_SCROLL_VIEW_PROP(scrollsToTop); +#endif MAP_SCROLL_VIEW_PROP(showsHorizontalScrollIndicator); MAP_SCROLL_VIEW_PROP(showsVerticalScrollIndicator); diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm index 79ee7ffe434..07fb9c4e7b6 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm @@ -34,11 +34,16 @@ using namespace facebook::react; @end +#if !TARGET_OS_TV @interface RCTParagraphComponentView () @property (nonatomic, nullable) UIEditMenuInteraction *editMenuInteraction API_AVAILABLE(ios(16.0)); @end +#else +@interface RCTParagraphComponentView () +@end +#endif @implementation RCTParagraphComponentView { ParagraphAttributes _paragraphAttributes; @@ -280,6 +285,7 @@ using namespace facebook::react; #pragma mark - Context Menu +#if !TARGET_OS_TV - (void)enableContextMenu { _longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self @@ -357,6 +363,15 @@ using namespace facebook::react; UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; pasteboard.items = @[ item ]; } +#else +- (void)enableContextMenu +{ +} + +- (void)disableContextMenu +{ +} +#endif @end diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm index a3947e808a3..d338f164937 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm @@ -378,6 +378,7 @@ const CGFloat BACKGROUND_COLOR_ZPOSITION = -1024.0f; // `accessibilityShowsLargeContentViewer` if (oldViewProps.accessibilityShowsLargeContentViewer != newViewProps.accessibilityShowsLargeContentViewer) { +#if !TARGET_OS_TV if (@available(iOS 13.0, *)) { if (newViewProps.accessibilityShowsLargeContentViewer) { self.showsLargeContentViewer = YES; @@ -387,13 +388,16 @@ const CGFloat BACKGROUND_COLOR_ZPOSITION = -1024.0f; self.showsLargeContentViewer = NO; } } +#endif } // `accessibilityLargeContentTitle` if (oldViewProps.accessibilityLargeContentTitle != newViewProps.accessibilityLargeContentTitle) { +#if !TARGET_OS_TV if (@available(iOS 13.0, *)) { self.largeContentTitle = RCTNSStringFromStringNilIfEmpty(newViewProps.accessibilityLargeContentTitle); } +#endif } // `accessibilityOrder` @@ -941,7 +945,8 @@ static RCTBorderStyle RCTBorderStyleFromOutlineStyle(OutlineStyle outlineStyle) layer.shadowPath = nil; } -#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000 /* __IPHONE_17_0 */ +#if !TARGET_OS_TV && defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && \ + __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000 /* __IPHONE_17_0 */ // Stage 1.5. Cursor / Hover Effects if (@available(iOS 17.0, *)) { UIHoverStyle *hoverStyle = nil; diff --git a/packages/react-native/React/Modules/RCTLayoutAnimation.m b/packages/react-native/React/Modules/RCTLayoutAnimation.m index d88fa0fba69..e263e576fec 100644 --- a/packages/react-native/React/Modules/RCTLayoutAnimation.m +++ b/packages/react-native/React/Modules/RCTLayoutAnimation.m @@ -33,6 +33,14 @@ static UIViewAnimationOptions UIViewAnimationOptionsFromRCTAnimationType(RCTAnim } } +#if TARGET_OS_TV + +// No-op on tvOS ++ (void)initializeStatics +{ +} + +#else // Use a custom initialization function rather than implementing `+initialize` so that we can control // when the initialization code runs. `+initialize` runs immediately before the first message is sent // to the class which may be too late for us. By this time, we may have missed some @@ -54,6 +62,8 @@ static UIViewAnimationOptions UIViewAnimationOptionsFromRCTAnimationType(RCTAnim _currentKeyboardAnimationCurve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue]; } +#endif + - (instancetype)initWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay property:(NSString *)property diff --git a/packages/react-native/React/Profiler/RCTProfile.m b/packages/react-native/React/Profiler/RCTProfile.m index 04d6ac14ec9..2d5ddaf7618 100644 --- a/packages/react-native/React/Profiler/RCTProfile.m +++ b/packages/react-native/React/Profiler/RCTProfile.m @@ -393,6 +393,7 @@ void RCTProfileUnhookModules(RCTBridge *bridge) RCTProfileEnd(RCTProfilingBridge(), ^(NSString *result) { NSString *outFile = [NSTemporaryDirectory() stringByAppendingString:@"tmp_trace.json"]; [result writeToFile:outFile atomically:YES encoding:NSUTF8StringEncoding error:nil]; +#if !TARGET_OS_TV UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[ [NSURL fileURLWithPath:outFile] ] applicationActivities:nil]; @@ -409,6 +410,9 @@ void RCTProfileUnhookModules(RCTBridge *bridge) animated:YES completion:nil]; }); +#else + RCTProfileControlsWindow.hidden = NO; +#endif }); } else { RCTProfileInit(RCTProfilingBridge());