From 3bc9a5cacbd02ae73b51945c577872b0b5ca9114 Mon Sep 17 00:00:00 2001 From: Devan Buggay Date: Fri, 16 Jan 2026 13:54:04 -0800 Subject: [PATCH] Stub unsupported components for AppleTV (#55198) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55198 UISwitch, UIRefreshControl, UIKeyboardNotifications ,and UIPasteBoard are unavailable on AppleTV https://developer.apple.com/documentation/uikit/uiswitch?language=objc https://developer.apple.com/documentation/uikit/uirefreshcontrol?language=objc https://developer.apple.com/documentation/uikit/uiresponder/keyboardwillshownotification?language=objc https://developer.apple.com/documentation/uikit/uipasteboard?language=objc Changelog: [Internal] Reviewed By: javache Differential Revision: D90712066 fbshipit-source-id: 045836f14e650c655ae669bf5e3bb7fcf693efd3 --- packages/react-native/React/Base/RCTUtils.mm | 4 +++ .../CoreModules/RCTActionSheetManager.mm | 31 +++++++++++++++++-- .../React/CoreModules/RCTClipboard.mm | 6 ++++ .../React/CoreModules/RCTKeyboardObserver.mm | 11 +++++++ .../RCTPullToRefreshViewComponentView.mm | 18 +++++++++++ .../Switch/RCTSwitchComponentView.mm | 15 +++++++++ 6 files changed, 82 insertions(+), 3 deletions(-) diff --git a/packages/react-native/React/Base/RCTUtils.mm b/packages/react-native/React/Base/RCTUtils.mm index 8744d6fb798..ac3136e10b5 100644 --- a/packages/react-native/React/Base/RCTUtils.mm +++ b/packages/react-native/React/Base/RCTUtils.mm @@ -421,6 +421,10 @@ CGSize RCTViewportSize(void) CGSize RCTSwitchSize(void) { + // UISwitch is not supported on AppleTV +#if TARGET_OS_TV + return CGSizeMake(0, 0); +#endif static CGSize rctSwitchSize; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ diff --git a/packages/react-native/React/CoreModules/RCTActionSheetManager.mm b/packages/react-native/React/CoreModules/RCTActionSheetManager.mm index 6472cc44f0b..360b366ccc3 100644 --- a/packages/react-native/React/CoreModules/RCTActionSheetManager.mm +++ b/packages/react-native/React/CoreModules/RCTActionSheetManager.mm @@ -7,17 +7,20 @@ #import +#import + +#import "CoreModulesPlugins.h" + +#if !TARGET_OS_TV + #import #import #import #import #import -#import #import -#import "CoreModulesPlugins.h" - using namespace facebook::react; @interface RCTActionSheetManager () @@ -313,6 +316,28 @@ RCT_EXPORT_METHOD( @end +#else + +using namespace facebook::react; + +@implementation RCTActionSheetManager + +RCT_EXPORT_MODULE() + ++ (BOOL)requiresMainQueueSetup +{ + return NO; +} + +- (std::shared_ptr)getTurboModule:(const ObjCTurboModule::InitParams &)params +{ + return std::make_shared(params); +} + +@end + +#endif + Class RCTActionSheetManagerCls(void) { return RCTActionSheetManager.class; diff --git a/packages/react-native/React/CoreModules/RCTClipboard.mm b/packages/react-native/React/CoreModules/RCTClipboard.mm index 2dc098a4730..f057c34f704 100644 --- a/packages/react-native/React/CoreModules/RCTClipboard.mm +++ b/packages/react-native/React/CoreModules/RCTClipboard.mm @@ -28,14 +28,20 @@ RCT_EXPORT_MODULE() RCT_EXPORT_METHOD(setString : (NSString *)content) { +#if !TARGET_OS_TV UIPasteboard *clipboard = [UIPasteboard generalPasteboard]; clipboard.string = (content ?: @""); +#endif } RCT_EXPORT_METHOD(getString : (RCTPromiseResolveBlock)resolve reject : (__unused RCTPromiseRejectBlock)reject) { +#if !TARGET_OS_TV UIPasteboard *clipboard = [UIPasteboard generalPasteboard]; resolve((clipboard.string ?: @"")); +#else + resolve(@""); +#endif } - (std::shared_ptr)getTurboModule:(const ObjCTurboModule::InitParams &)params diff --git a/packages/react-native/React/CoreModules/RCTKeyboardObserver.mm b/packages/react-native/React/CoreModules/RCTKeyboardObserver.mm index 79f4f8f4170..ccaf9a84da8 100644 --- a/packages/react-native/React/CoreModules/RCTKeyboardObserver.mm +++ b/packages/react-native/React/CoreModules/RCTKeyboardObserver.mm @@ -24,6 +24,7 @@ RCT_EXPORT_MODULE() - (void)startObserving { +#if !TARGET_OS_TV NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; #define ADD_KEYBOARD_HANDLER(NAME, SELECTOR) [nc addObserver:self selector:@selector(SELECTOR:) name:NAME object:nil] @@ -36,6 +37,7 @@ RCT_EXPORT_MODULE() ADD_KEYBOARD_HANDLER(UIKeyboardDidChangeFrameNotification, keyboardDidChangeFrame); #undef ADD_KEYBOARD_HANDLER +#endif } - (NSArray *)supportedEvents @@ -82,6 +84,7 @@ IMPLEMENT_KEYBOARD_HANDLER(keyboardDidChangeFrame) @end +#if !TARGET_OS_TV NS_INLINE NSDictionary *RCTRectDictionaryValue(CGRect rect) { return @{ @@ -131,6 +134,14 @@ static NSDictionary *RCTParseKeyboardNotification(NSNotification *notification) }; } +#else +static NSDictionary *RCTParseKeyboardNotification(NSNotification *notification) +{ + return @{}; +} + +#endif + Class RCTKeyboardObserverCls(void) { return RCTKeyboardObserver.class; diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm index 36338f61b29..60160efb163 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm @@ -23,6 +23,22 @@ using namespace facebook::react; @interface RCTPullToRefreshViewComponentView () @end +#if TARGET_OS_TV + +@implementation RCTPullToRefreshViewComponentView + +- (void)setNativeRefreshing:(BOOL)refreshing +{ +} + +- (void)setRefreshing:(BOOL)refreshing +{ +} + +@end + +#else + @implementation RCTPullToRefreshViewComponentView { UIRefreshControl *_refreshControl; RCTScrollViewComponentView *__weak _scrollViewComponentView; @@ -259,6 +275,8 @@ using namespace facebook::react; @end +#endif + Class RCTPullToRefreshViewCls(void) { return RCTPullToRefreshViewComponentView.class; diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm index ba836bf5fd4..a7484b3b05f 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm @@ -21,6 +21,19 @@ using namespace facebook::react; @interface RCTSwitchComponentView () @end +#if TARGET_OS_TV + +@implementation RCTSwitchComponentView { +} + +- (void)setValue:(BOOL)value +{ +} + +@end + +#else + @implementation RCTSwitchComponentView { UISwitch *_switchView; BOOL _isInitialValueSet; @@ -127,6 +140,8 @@ using namespace facebook::react; @end +#endif + Class RCTSwitchCls(void) { return RCTSwitchComponentView.class;