Skip to content

Commit

Permalink
fix (iOS): Only try to make the alert window key if the app recognize…
Browse files Browse the repository at this point in the history
…s it (microsoft#1008)
  • Loading branch information
amgleitman committed Feb 5, 2022
1 parent 26957c1 commit 799cdb2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions React/CoreModules/RCTAlertController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ - (UIWindow *)alertWindow

- (void)show:(BOOL)animated completion:(void (^)(void))completion
{
[self.alertWindow makeKeyAndVisible];

// [TODO(macOS GH#774)
// Call self.alertWindow to ensure that it gets populated
UIWindow *alertWindow = self.alertWindow;

// If the window is tracked by our application then it will show the alert
if ([[[UIApplication sharedApplication] windows] containsObject:self.alertWindow]) {
[self.alertWindow.rootViewController presentViewController:self animated:animated completion:completion];
if ([[[UIApplication sharedApplication] windows] containsObject:alertWindow]) {
// On iOS 14, makeKeyAndVisible should only be called if alertWindow is tracked by the application.
// Later versions of iOS appear to already do this check for us behind the scenes.
[alertWindow makeKeyAndVisible];
[alertWindow.rootViewController presentViewController:self animated:animated completion:completion];
} else {
// When using Scenes, we must present the alert from a view controller associated with a window in the Scene. A fresh window (i.e. _alertWindow) cannot show the alert.
[RCTPresentedViewController() presentViewController:self animated:animated completion:completion];
Expand Down

0 comments on commit 799cdb2

Please sign in to comment.