Skip to content

Commit

Permalink
Fix retrieving current appearance in multi-window apps (#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.

## Changelog:

[IOS] [FIXED] - Fix retrieving current appearance in multi-window apps

Pull Request resolved: #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 facebook-github-bot committed Jan 30, 2024
1 parent fb5f79c commit d00d35e
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 @@ -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;
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 @@ -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:)
Expand Down

0 comments on commit d00d35e

Please sign in to comment.