Skip to content

Commit ae7bbe0

Browse files
okwasniewskifacebook-github-bot
authored andcommitted
fix: make React Native work without AppDelegate window property (facebook#49748)
Summary: This PR makes React Native not relying on the `window` property in AppDelegate. When running in SwiftUI lifecycle mode / SceneDelegate mode there is window property on AppDelegate. This PR fixes crashes that happen because RN asserts window property is there. ## Changelog: [IOS] [FIXED] - make React Native work without AppDelegate window property Pull Request resolved: facebook#49748 Test Plan: CI Green Reviewed By: javache Differential Revision: D70389691 Pulled By: cipolleschi fbshipit-source-id: fe39f123b47014ba91a080239ccd298192c92a6a
1 parent 7ccb1e1 commit ae7bbe0

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

packages/react-native/React/Base/UIKitProxies/RCTWindowSafeAreaProxy.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ - (void)startObservingSafeArea
3434
std::lock_guard<std::mutex> lock(_mutex);
3535
if (!_isObserving) {
3636
_isObserving = YES;
37-
_currentSafeAreaInsets = [UIApplication sharedApplication].delegate.window.safeAreaInsets;
37+
_currentSafeAreaInsets = RCTKeyWindow().safeAreaInsets;
3838
[[NSNotificationCenter defaultCenter] addObserver:self
3939
selector:@selector(_interfaceFrameDidChange)
4040
name:RCTUserInterfaceStyleDidChangeNotification
@@ -64,7 +64,7 @@ - (UIEdgeInsets)currentSafeAreaInsets
6464
- (void)_interfaceFrameDidChange
6565
{
6666
std::lock_guard<std::mutex> lock(_mutex);
67-
_currentSafeAreaInsets = [UIApplication sharedApplication].delegate.window.safeAreaInsets;
67+
_currentSafeAreaInsets = RCTKeyWindow().safeAreaInsets;
6868
}
6969

7070
@end

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,10 @@ - (void)didReceiveNewContentSizeMultiplier
209209
- (void)interfaceOrientationDidChange
210210
{
211211
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
212-
UIApplication *application = RCTSharedApplication();
213-
UIInterfaceOrientation nextOrientation = RCTKeyWindow().windowScene.interfaceOrientation;
212+
UIWindow *keyWindow = RCTKeyWindow();
213+
UIInterfaceOrientation nextOrientation = keyWindow.windowScene.interfaceOrientation;
214214

215-
BOOL isRunningInFullScreen =
216-
CGRectEqualToRect(application.delegate.window.frame, application.delegate.window.screen.bounds);
215+
BOOL isRunningInFullScreen = CGRectEqualToRect(keyWindow.frame, keyWindow.screen.bounds);
217216
// We are catching here two situations for multitasking view:
218217
// a) The app is in Split View and the container gets resized -> !isRunningInFullScreen
219218
// b) The app changes to/from fullscreen example: App runs in slide over mode and goes into fullscreen->

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ - (NSInteger)bottomSafeViewHeight
222222
#if TARGET_OS_MACCATALYST
223223
return 0;
224224
#else
225-
return RCTSharedApplication().delegate.window.safeAreaInsets.bottom;
225+
return RCTKeyWindow().safeAreaInsets.bottom;
226226
#endif
227227
}
228228

0 commit comments

Comments
 (0)