Skip to content

Commit

Permalink
Fix retrieving current appearance in multi-window apps (facebook#42231)
Browse files Browse the repository at this point in the history
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: facebook#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
  • Loading branch information
okwasniewski authored and Saadnajmi committed May 22, 2024
1 parent bb2770d commit 30336ea
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions packages/react-native/React/CoreModules/RCTAlertController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/React/CoreModules/RCTAppearance.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 30336ea

Please sign in to comment.