Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions packages/react-native/React/Base/RCTUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#import "RCTUtils.h"

#import <atomic>
#import <dlfcn.h>
#import <mach/mach_time.h>
#import <objc/message.h>
Expand Down Expand Up @@ -383,24 +384,26 @@ UIDeviceOrientation RCTDeviceOrientation(void)

CGSize RCTScreenSize(void)
{
static CGSize portraitSize;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
static std::atomic<CGSize> cachedSize;
__block CGSize size = cachedSize.load(std::memory_order_relaxed);

if (CGSizeEqualToSize(size, CGSizeZero)) {
RCTUnsafeExecuteOnMainQueueSync(^{
CGSize screenSize = [UIScreen mainScreen].bounds.size;
portraitSize = CGSizeMake(MIN(screenSize.width, screenSize.height), MAX(screenSize.width, screenSize.height));
size = CGSizeMake(MIN(screenSize.width, screenSize.height), MAX(screenSize.width, screenSize.height));
cachedSize.store(size, std::memory_order_relaxed);
});
});
}

#if !TARGET_OS_TV
if (UIDeviceOrientationIsLandscape(RCTDeviceOrientation())) {
return CGSizeMake(portraitSize.height, portraitSize.width);
return CGSizeMake(size.height, size.width);
} else {
return CGSizeMake(portraitSize.width, portraitSize.height);
return CGSizeMake(size.width, size.height);
}
#else
// tvOS doesn't have device orientation, always return landscape size
return CGSizeMake(portraitSize.height, portraitSize.width);
return CGSizeMake(size.height, size.width);
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ - (UIWindow *)alertWindow
UIWindowScene *scene = RCTKeyWindow().windowScene;
if (scene != nil) {
_alertWindow = [[UIWindow alloc] initWithWindowScene:scene];
_alertWindow.frame = scene.coordinateSpace.bounds;
} else {
_alertWindow = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
}
Expand Down
Loading