From 2c55433cbf3bab7dbc639b71bf0aa656dd0ac892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwas=CC=81niewski?= Date: Tue, 30 Jan 2024 04:52:34 -0800 Subject: [PATCH] Fix retrieving current appearance in multi-window apps (#42231) Summary: This PR resolves issues with retrieving appearance in multi-window apps by calling `RCTKeyWindow()` instead of retrieving the AppDelegate window property. It also does small optimization in the RCTAlertController. [IOS] [FIXED] - Fix retrieving current appearance in multi-window apps Pull Request resolved: https://github.com/facebook/react-native/pull/42231 Test Plan: CI Green, it should work the same as before Reviewed By: NickGerleman Differential Revision: D52802756 Pulled By: cipolleschi fbshipit-source-id: 60b5f7045f41be19caae5102f0dc321d4ecdcd2f --- .../react-native/React/CoreModules/RCTAlertController.mm | 5 ++--- packages/react-native/React/CoreModules/RCTAppearance.mm | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/react-native/React/CoreModules/RCTAlertController.mm b/packages/react-native/React/CoreModules/RCTAlertController.mm index 7999a937e697bd..16334d1bdf2fda 100644 --- a/packages/react-native/React/CoreModules/RCTAlertController.mm +++ b/packages/react-native/React/CoreModules/RCTAlertController.mm @@ -38,9 +38,8 @@ - (void)show:(BOOL)animated completion:(void (^)(void))completion { UIUserInterfaceStyle style = self.overrideUserInterfaceStyle; if (style == UIUserInterfaceStyleUnspecified) { - style = RCTSharedApplication().delegate.window.overrideUserInterfaceStyle - ? RCTSharedApplication().delegate.window.overrideUserInterfaceStyle - : UIUserInterfaceStyleUnspecified; + UIUserInterfaceStyle overriddenStyle = RCTKeyWindow().overrideUserInterfaceStyle; + style = overriddenStyle ? overriddenStyle : UIUserInterfaceStyleUnspecified; } self.overrideUserInterfaceStyle = style; diff --git a/packages/react-native/React/CoreModules/RCTAppearance.mm b/packages/react-native/React/CoreModules/RCTAppearance.mm index 0a0c21e1c2c521..ad2aa9f63afb00 100644 --- a/packages/react-native/React/CoreModules/RCTAppearance.mm +++ b/packages/react-native/React/CoreModules/RCTAppearance.mm @@ -96,7 +96,7 @@ - (instancetype)init { if ((self = [super init])) { #if !TARGET_OS_OSX // [macOS] - UITraitCollection *traitCollection = RCTSharedApplication().delegate.window.traitCollection; + UITraitCollection *traitCollection = RCTKeyWindow().traitCollection; _currentColorScheme = RCTColorSchemePreference(traitCollection); #else // [macOS NSAppearance *appearance = RCTSharedApplication().appearance;