Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (iOS): Only try to make the alert window key if the app recognizes it #1008

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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];
amgleitman marked this conversation as resolved.
Show resolved Hide resolved
} 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