From f6cad6a526d6edd8778133c0e3b7b9b8d99e6068 Mon Sep 17 00:00:00 2001 From: Adam Gleitman Date: Fri, 4 Feb 2022 14:56:17 -0800 Subject: [PATCH 1/2] Only make the alert window key if the app knows about it --- React/CoreModules/RCTAlertController.m | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/React/CoreModules/RCTAlertController.m b/React/CoreModules/RCTAlertController.m index daf32a394dd272..6b5266fb5d22c1 100644 --- a/React/CoreModules/RCTAlertController.m +++ b/React/CoreModules/RCTAlertController.m @@ -32,12 +32,16 @@ - (UIWindow *)alertWindow - (void)show:(BOOL)animated completion:(void (^)(void))completion { - [self.alertWindow makeKeyAndVisible]; + // Call self.alertWindow to ensure that it gets populated + UIWindow *alertWindow = self.alertWindow; // [TODO(macOS GH#774) // 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]; From 3f0ee8230e906cf272232b693d583fd6862d2618 Mon Sep 17 00:00:00 2001 From: Adam Gleitman Date: Fri, 4 Feb 2022 16:54:43 -0800 Subject: [PATCH 2/2] Move call to self.alertWindow inside TODO tag --- React/CoreModules/RCTAlertController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/React/CoreModules/RCTAlertController.m b/React/CoreModules/RCTAlertController.m index 6b5266fb5d22c1..9903922edc4b9b 100644 --- a/React/CoreModules/RCTAlertController.m +++ b/React/CoreModules/RCTAlertController.m @@ -32,10 +32,10 @@ - (UIWindow *)alertWindow - (void)show:(BOOL)animated completion:(void (^)(void))completion { + // [TODO(macOS GH#774) // Call self.alertWindow to ensure that it gets populated UIWindow *alertWindow = self.alertWindow; - // [TODO(macOS GH#774) // If the window is tracked by our application then it will show the alert if ([[[UIApplication sharedApplication] windows] containsObject:alertWindow]) { // On iOS 14, makeKeyAndVisible should only be called if alertWindow is tracked by the application.