From 36d794d07032195c674b11737adc2e99970bb1f1 Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Mon, 23 Jan 2023 21:22:07 -0800 Subject: [PATCH 1/2] fix (iOS): Only try to make the alert window key if the app recognizes it --- React/CoreModules/RCTAlertController.m | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/React/CoreModules/RCTAlertController.m b/React/CoreModules/RCTAlertController.m index 3387a6e8d97c04..da16d147387329 100644 --- a/React/CoreModules/RCTAlertController.m +++ b/React/CoreModules/RCTAlertController.m @@ -48,8 +48,18 @@ - (void)show:(BOOL)animated completion:(void (^)(void))completion RCTSharedApplication().delegate.window.overrideUserInterfaceStyle ?: UIUserInterfaceStyleUnspecified; self.overrideUserInterfaceStyle = style; } - [self.alertWindow makeKeyAndVisible]; - [self.alertWindow.rootViewController presentViewController:self animated:animated completion:completion]; + // 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: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]; } - (void)hide From 80a01142b0797a8eda075ac901a315255cd8f597 Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Wed, 25 Jan 2023 10:37:53 -0800 Subject: [PATCH 2/2] Update RCTAlertController.m --- React/CoreModules/RCTAlertController.m | 1 + 1 file changed, 1 insertion(+) diff --git a/React/CoreModules/RCTAlertController.m b/React/CoreModules/RCTAlertController.m index da16d147387329..6c617606569aaf 100644 --- a/React/CoreModules/RCTAlertController.m +++ b/React/CoreModules/RCTAlertController.m @@ -60,6 +60,7 @@ - (void)show:(BOOL)animated completion:(void (^)(void))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]; + } } - (void)hide