From d00d35e8723293b0c1e098fa2e02756884a0f7f9 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. ## Changelog: [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 5c661e6fce12d4..b47ce0adefa06f 100644 --- a/packages/react-native/React/CoreModules/RCTAlertController.mm +++ b/packages/react-native/React/CoreModules/RCTAlertController.mm @@ -35,9 +35,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 543bc1b791bead..2ad68a589464e2 100644 --- a/packages/react-native/React/CoreModules/RCTAppearance.mm +++ b/packages/react-native/React/CoreModules/RCTAppearance.mm @@ -70,7 +70,7 @@ @implementation RCTAppearance { - (instancetype)init { if ((self = [super init])) { - UITraitCollection *traitCollection = RCTSharedApplication().delegate.window.traitCollection; + UITraitCollection *traitCollection = RCTKeyWindow().traitCollection; _currentColorScheme = RCTColorSchemePreference(traitCollection); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appearanceChanged:)