diff --git a/packages/react-native/React/Base/RCTUtils.mm b/packages/react-native/React/Base/RCTUtils.mm index 8744d6fb798e..ac3136e10b5d 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 6472cc44f0bc..360b366ccc3e 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 @@ - (void)presentViewController:(UIViewController *)alertController @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 2dc098a47302..f057c34f704c 100644 --- a/packages/react-native/React/CoreModules/RCTClipboard.mm +++ b/packages/react-native/React/CoreModules/RCTClipboard.mm @@ -28,14 +28,20 @@ - (dispatch_queue_t)methodQueue 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 79f4f8f4170f..ccaf9a84da89 100644 --- a/packages/react-native/React/CoreModules/RCTKeyboardObserver.mm +++ b/packages/react-native/React/CoreModules/RCTKeyboardObserver.mm @@ -24,6 +24,7 @@ @implementation RCTKeyboardObserver - (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 @@ - (void)startObserving ADD_KEYBOARD_HANDLER(UIKeyboardDidChangeFrameNotification, keyboardDidChangeFrame); #undef ADD_KEYBOARD_HANDLER +#endif } - (NSArray *)supportedEvents @@ -82,6 +84,7 @@ -(void)EVENT : (NSNotification *)notification @end +#if !TARGET_OS_TV NS_INLINE NSDictionary *RCTRectDictionaryValue(CGRect rect) { return @{ @@ -131,6 +134,14 @@ -(void)EVENT : (NSNotification *)notification }; } +#else +static NSDictionary *RCTParseKeyboardNotification(NSNotification *notification) +{ + return @{}; +} + +#endif + Class RCTKeyboardObserverCls(void) { return RCTKeyboardObserver.class; diff --git a/packages/react-native/React/CoreModules/RCTLogBoxView.mm b/packages/react-native/React/CoreModules/RCTLogBoxView.mm index 3b003a28a5dd..79f9aa288a4f 100644 --- a/packages/react-native/React/CoreModules/RCTLogBoxView.mm +++ b/packages/react-native/React/CoreModules/RCTLogBoxView.mm @@ -20,7 +20,9 @@ @implementation RCTLogBoxView { - (instancetype)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame]) != nullptr) { +#if !TARGET_OS_TV self.windowLevel = UIWindowLevelStatusBar - 1; +#endif self.backgroundColor = [UIColor clearColor]; } return self; @@ -40,7 +42,9 @@ - (instancetype)initWithWindow:(UIWindow *)window bridge:(RCTBridge *)bridge { self = [super initWithWindowScene:window.windowScene]; +#if !TARGET_OS_TV self.windowLevel = UIWindowLevelStatusBar - 1; +#endif self.backgroundColor = [UIColor clearColor]; _surface = [[RCTSurface alloc] initWithBridge:bridge moduleName:@"LogBox" initialProperties:@{}]; diff --git a/packages/react-native/React/CoreModules/RCTRedBox.mm b/packages/react-native/React/CoreModules/RCTRedBox.mm index fb057b969214..f0dbb32bad1b 100644 --- a/packages/react-native/React/CoreModules/RCTRedBox.mm +++ b/packages/react-native/React/CoreModules/RCTRedBox.mm @@ -108,8 +108,10 @@ - (void)viewDidLoad _stackTraceTableView.delegate = self; _stackTraceTableView.dataSource = self; _stackTraceTableView.backgroundColor = [UIColor clearColor]; +#if !TARGET_OS_TV _stackTraceTableView.separatorColor = [UIColor colorWithWhite:1 alpha:0.3]; _stackTraceTableView.separatorStyle = UITableViewCellSeparatorStyleNone; +#endif _stackTraceTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite; [self.view addSubview:_stackTraceTableView]; @@ -308,8 +310,10 @@ - (void)copyStack [fullStackTrace appendFormat:@" %@\n", [self formatFrameSource:stackFrame]]; } } +#if !TARGET_OS_TV UIPasteboard *pb = [UIPasteboard generalPasteboard]; [pb setString:fullStackTrace]; +#endif } - (NSString *)formatFrameSource:(RCTJSStackFrame *)stackFrame diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/InputAccessory/RCTInputAccessoryComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/InputAccessory/RCTInputAccessoryComponentView.mm index 9f1f29918a57..cde96f038792 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/InputAccessory/RCTInputAccessoryComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/InputAccessory/RCTInputAccessoryComponentView.mm @@ -43,7 +43,9 @@ @implementation RCTInputAccessoryComponentView { InputAccessoryShadowNode::ConcreteState::Shared _state; RCTInputAccessoryContentView *_contentView; +#if !TARGET_OS_TV RCTSurfaceTouchHandler *_touchHandler; +#endif UIView __weak *_textInput; } @@ -52,8 +54,10 @@ - (instancetype)initWithFrame:(CGRect)frame if (self = [super initWithFrame:frame]) { _props = InputAccessoryShadowNode::defaultSharedProps(); _contentView = [RCTInputAccessoryContentView new]; +#if !TARGET_OS_TV _touchHandler = [RCTSurfaceTouchHandler new]; [_touchHandler attachToView:_contentView]; +#endif } return self; diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTFabricModalHostViewController.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTFabricModalHostViewController.mm index 16b71e4d64ec..1a4339065e60 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTFabricModalHostViewController.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTFabricModalHostViewController.mm @@ -12,7 +12,9 @@ @implementation RCTFabricModalHostViewController { CGRect _lastViewBounds; +#if !TARGET_OS_TV RCTSurfaceTouchHandler *_touchHandler; +#endif } - (instancetype)init @@ -20,7 +22,9 @@ - (instancetype)init if ((self = [super init]) == nullptr) { return nil; } +#if !TARGET_OS_TV _touchHandler = [RCTSurfaceTouchHandler new]; +#endif return self; } @@ -37,7 +41,9 @@ - (void)viewDidLayoutSubviews - (void)loadView { self.view = [UIView new]; +#if !TARGET_OS_TV [_touchHandler attachToView:self.view]; +#endif } - (UIStatusBarStyle)preferredStatusBarStyle 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 36338f61b29b..60160efb163d 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 @@ @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 @@ - (NSString *)componentViewName_DO_NOT_USE_THIS_IS_BROKEN @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 ba836bf5fd44..a7484b3b05fb 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 @@ @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 @@ - (void)setValue:(BOOL)value @end +#endif + Class RCTSwitchCls(void) { return RCTSwitchComponentView.class; diff --git a/packages/react-native/React/Fabric/RCTSurfacePointerHandler.mm b/packages/react-native/React/Fabric/RCTSurfacePointerHandler.mm index d752d6ae56b7..fe00a0b3e951 100644 --- a/packages/react-native/React/Fabric/RCTSurfacePointerHandler.mm +++ b/packages/react-native/React/Fabric/RCTSurfacePointerHandler.mm @@ -15,6 +15,8 @@ #import "RCTConversions.h" #import "RCTTouchableComponentViewProtocol.h" +#if !TARGET_OS_TV + using namespace facebook::react; typedef NS_ENUM(NSInteger, RCTPointerEventType) { @@ -771,3 +773,5 @@ - (void)hovering:(UIHoverGestureRecognizer *)recognizer } @end + +#endif // !TARGET_OS_TV diff --git a/packages/react-native/React/Fabric/RCTSurfaceTouchHandler.mm b/packages/react-native/React/Fabric/RCTSurfaceTouchHandler.mm index d8c709fd5061..ea2952c23e78 100644 --- a/packages/react-native/React/Fabric/RCTSurfaceTouchHandler.mm +++ b/packages/react-native/React/Fabric/RCTSurfaceTouchHandler.mm @@ -15,6 +15,8 @@ #import "RCTSurfacePointerHandler.h" #import "RCTTouchableComponentViewProtocol.h" +#if !TARGET_OS_TV + using namespace facebook::react; typedef NS_ENUM(NSInteger, RCTTouchEventType) { @@ -414,3 +416,5 @@ - (void)_cancelTouches } @end + +#endif // !TARGET_OS_TV diff --git a/packages/react-native/React/Fabric/Surface/RCTFabricSurface.mm b/packages/react-native/React/Fabric/Surface/RCTFabricSurface.mm index cf932b52bf00..2a5a3a66346f 100644 --- a/packages/react-native/React/Fabric/Surface/RCTFabricSurface.mm +++ b/packages/react-native/React/Fabric/Surface/RCTFabricSurface.mm @@ -45,7 +45,9 @@ @implementation RCTFabricSurface { // Can be accessed from the main thread only. RCTSurfaceView *_Nullable _view; +#if !TARGET_OS_TV RCTSurfaceTouchHandler *_Nullable _touchHandler; +#endif } @synthesize delegate = _delegate; @@ -144,8 +146,10 @@ - (RCTSurfaceView *)view if (!_view) { _view = [[RCTSurfaceView alloc] initWithSurface:self]; [self _updateLayoutContext]; +#if !TARGET_OS_TV _touchHandler = [RCTSurfaceTouchHandler new]; [_touchHandler attachToView:_view]; +#endif } return _view; diff --git a/packages/react-native/React/Modules/RCTRedBoxExtraDataViewController.m b/packages/react-native/React/Modules/RCTRedBoxExtraDataViewController.m index 6afd630eac28..c3c089d85989 100644 --- a/packages/react-native/React/Modules/RCTRedBoxExtraDataViewController.m +++ b/packages/react-native/React/Modules/RCTRedBoxExtraDataViewController.m @@ -108,7 +108,9 @@ - (void)viewDidLoad _tableView.delegate = self; _tableView.dataSource = self; _tableView.backgroundColor = [UIColor colorWithRed:0.8 green:0 blue:0 alpha:1]; +#if !TARGET_OS_TV _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; +#endif _tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite; _tableView.allowsSelection = NO; [self.view addSubview:_tableView];