Skip to content

Commit abdcb92

Browse files
sbuggayfacebook-github-bot
authored andcommitted
Compile out orientation usage for AppleTV (#55128)
Summary: UIOrientation usage is unsupported on AppleTV, compiling out. Changelog: [internal] Reviewed By: Abbondanzo Differential Revision: D90513975
1 parent 1ee95da commit abdcb92

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

packages/react-native/React/Base/RCTUtils.mm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
BOOL RCTIsHomeAssetURL(NSURL *__nullable imageURL);
3939

4040
// Returns the current device's orientation
41+
#if !TARGET_OS_TV
4142
UIDeviceOrientation RCTDeviceOrientation(void);
43+
#endif
4244

4345
// Whether the New Architecture is enabled or not
4446
BOOL RCTIsNewArchEnabled(void)
@@ -381,10 +383,12 @@ CGFloat RCTFontSizeMultiplier(void)
381383
return mapping[RCTSharedApplication().preferredContentSizeCategory].floatValue;
382384
}
383385

386+
#if !TARGET_OS_TV
384387
UIDeviceOrientation RCTDeviceOrientation(void)
385388
{
386389
return [[UIDevice currentDevice] orientation];
387390
}
391+
#endif
388392

389393
CGSize RCTScreenSize(void)
390394
{
@@ -397,11 +401,16 @@ CGSize RCTScreenSize(void)
397401
});
398402
});
399403

404+
#if !TARGET_OS_TV
400405
if (UIDeviceOrientationIsLandscape(RCTDeviceOrientation())) {
401406
return CGSizeMake(portraitSize.height, portraitSize.width);
402407
} else {
403408
return CGSizeMake(portraitSize.width, portraitSize.height);
404409
}
410+
#else
411+
// tvOS doesn't have device orientation, always return landscape size
412+
return CGSizeMake(portraitSize.height, portraitSize.width);
413+
#endif
405414
}
406415

407416
CGSize RCTViewportSize(void)

packages/react-native/React/CoreModules/RCTDeviceInfo.mm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ @interface RCTDeviceInfo () <NativeDeviceInfoSpec, RCTInitializing, RCTInvalidat
2525
@end
2626

2727
@implementation RCTDeviceInfo {
28+
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
2829
UIInterfaceOrientation _currentInterfaceOrientation;
30+
#endif
2931
NSDictionary *_currentInterfaceDimensions;
3032
BOOL _isFullscreen;
3133
std::atomic<BOOL> _invalidated;
@@ -103,10 +105,11 @@ - (void)initialize
103105
name:UIApplicationDidBecomeActiveNotification
104106
object:nil];
105107

106-
#if TARGET_OS_IOS
107-
108+
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
108109
_currentInterfaceOrientation = RCTKeyWindow().windowScene.interfaceOrientation;
110+
#endif
109111

112+
#if TARGET_OS_IOS
110113
[[NSNotificationCenter defaultCenter] addObserver:self
111114
selector:@selector(interfaceFrameDidChange)
112115
name:UIDeviceOrientationDidChangeNotification

packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
using namespace facebook::react;
2323

24+
#if !TARGET_OS_TV
2425
static UIInterfaceOrientationMask supportedOrientationsMask(ModalHostViewSupportedOrientationsMask mask)
2526
{
2627
UIInterfaceOrientationMask supportedOrientations = 0;
@@ -55,6 +56,7 @@ static UIInterfaceOrientationMask supportedOrientationsMask(ModalHostViewSupport
5556

5657
return supportedOrientations;
5758
}
59+
#endif
5860

5961
static std::tuple<BOOL, UIModalTransitionStyle> animationConfiguration(const ModalHostViewAnimationType animation)
6062
{
@@ -77,9 +79,21 @@ static UIModalPresentationStyle presentationConfiguration(const ModalHostViewPro
7779
case ModalHostViewPresentationStyle::FullScreen:
7880
return UIModalPresentationFullScreen;
7981
case ModalHostViewPresentationStyle::PageSheet:
82+
#if !TARGET_OS_TV
8083
return UIModalPresentationPageSheet;
84+
#else
85+
return UIModalPresentationFullScreen;
86+
#endif
8187
case ModalHostViewPresentationStyle::FormSheet:
88+
#if TARGET_OS_TV
89+
if (@available(tvOS 26.0, *)) {
90+
return UIModalPresentationFormSheet;
91+
} else {
92+
return UIModalPresentationFullScreen;
93+
}
94+
#else
8295
return UIModalPresentationFormSheet;
96+
#endif
8397
case ModalHostViewPresentationStyle::OverFullScreen:
8498
return UIModalPresentationOverFullScreen;
8599
}

packages/react-native/React/Modules/RCTUIManager.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ - (void)didReceiveNewContentSizeMultiplier
321321
});
322322
}
323323

324+
#if TARGET_OS_IOS
324325
// Names and coordinate system from html5 spec:
325326
// https://developer.mozilla.org/en-US/docs/Web/API/Screen.orientation
326327
// https://developer.mozilla.org/en-US/docs/Web/API/Screen.lockOrientation
@@ -360,7 +361,6 @@ - (void)didReceiveNewContentSizeMultiplier
360361
};
361362
}
362363

363-
#if TARGET_OS_IOS
364364
- (void)namedOrientationDidChange
365365
{
366366
NSDictionary *orientationEvent = deviceOrientationEventBody([UIDevice currentDevice].orientation);

0 commit comments

Comments
 (0)