Files
react-native/packages/react-native/React/Views/RCTModalHostViewController.m
T
Oskar Kwaśniewski 815c415fb9 refactor: supportedInterfaceOrientations method to use RCTKeyWindow() (#43026)
Summary:
This PR refactors `supportedInterfaceOrientations` to use RCTKeyWindow instead of `[RCTSharedApplication() keyWindow]`.

## Changelog:

[IOS] [CHANGED] - Refactor supportedInterfaceOrientations method to use RCTKeyWindow()

Pull Request resolved: https://github.com/facebook/react-native/pull/43026

Test Plan: CI Green

Reviewed By: dmytrorykun

Differential Revision: D59109614

Pulled By: cipolleschi

fbshipit-source-id: 025534c419078dce29e1e5caacf8a1b15de1abcc
2024-06-27 07:58:50 -07:00

73 lines
1.8 KiB
Objective-C

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTModalHostViewController.h"
#import "RCTLog.h"
#import "RCTModalHostView.h"
@implementation RCTModalHostViewController {
CGRect _lastViewFrame;
UIStatusBarStyle _preferredStatusBarStyle;
BOOL _preferredStatusBarHidden;
}
- (instancetype)init
{
if (!(self = [super init])) {
return nil;
}
self.modalInPresentation = YES;
_preferredStatusBarStyle = [RCTUIStatusBarManager() statusBarStyle];
_preferredStatusBarHidden = [RCTUIStatusBarManager() isStatusBarHidden];
return self;
}
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
if (self.boundsDidChangeBlock && !CGRectEqualToRect(_lastViewFrame, self.view.frame)) {
self.boundsDidChangeBlock(self.view.bounds);
_lastViewFrame = self.view.frame;
}
}
- (UIStatusBarStyle)preferredStatusBarStyle
{
return _preferredStatusBarStyle;
}
- (BOOL)prefersStatusBarHidden
{
return _preferredStatusBarHidden;
}
#if RCT_DEV
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
UIInterfaceOrientationMask appSupportedOrientationsMask =
[RCTSharedApplication() supportedInterfaceOrientationsForWindow:RCTKeyWindow()];
if (!(_supportedInterfaceOrientations & appSupportedOrientationsMask)) {
RCTLogError(
@"Modal was presented with 0x%x orientations mask but the application only supports 0x%x."
@"Add more interface orientations to your app's Info.plist to fix this."
@"NOTE: This will crash in non-dev mode.",
(unsigned)_supportedInterfaceOrientations,
(unsigned)appSupportedOrientationsMask);
return UIInterfaceOrientationMaskAll;
}
return _supportedInterfaceOrientations;
}
#endif // RCT_DEV
@end