Skip to content

Commit 2732ea2

Browse files
authored
fix (iOS): Only try to make the alert window key if the app recognizes it (#1008) (#1010)
1 parent 26957c1 commit 2732ea2

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

React/CoreModules/RCTAlertController.m

+8-4
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ - (UIWindow *)alertWindow
3232

3333
- (void)show:(BOOL)animated completion:(void (^)(void))completion
3434
{
35-
[self.alertWindow makeKeyAndVisible];
36-
3735
// [TODO(macOS GH#774)
36+
// Call self.alertWindow to ensure that it gets populated
37+
UIWindow *alertWindow = self.alertWindow;
38+
3839
// If the window is tracked by our application then it will show the alert
39-
if ([[[UIApplication sharedApplication] windows] containsObject:self.alertWindow]) {
40-
[self.alertWindow.rootViewController presentViewController:self animated:animated completion:completion];
40+
if ([[[UIApplication sharedApplication] windows] containsObject:alertWindow]) {
41+
// On iOS 14, makeKeyAndVisible should only be called if alertWindow is tracked by the application.
42+
// Later versions of iOS appear to already do this check for us behind the scenes.
43+
[alertWindow makeKeyAndVisible];
44+
[alertWindow.rootViewController presentViewController:self animated:animated completion:completion];
4145
} else {
4246
// 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.
4347
[RCTPresentedViewController() presentViewController:self animated:animated completion:completion];

0 commit comments

Comments
 (0)