Skip to content

Commit d02ace5

Browse files
committed
move alert changes
1 parent c8079a6 commit d02ace5

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

React/CoreModules/RCTAlertController.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,16 @@ - (UIWindow *)alertWindow
3333
- (void)show:(BOOL)animated completion:(void (^)(void))completion
3434
{
3535
[self.alertWindow makeKeyAndVisible];
36-
[self.alertWindow.rootViewController presentViewController:self animated:animated completion:completion];
36+
37+
// [TODO(macOS GH#774)
38+
// 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];
41+
} else {
42+
// 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.
43+
[RCTPresentedViewController() presentViewController:self animated:animated completion:completion];
44+
}
45+
// TODO(macOS GH#774)]
3746
}
3847
#endif // ]TODO(macOS GH#774)
3948

React/CoreModules/RCTAlertManager.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ - (void)invalidate
199199
[_alertControllers addObject:alertController];
200200

201201
dispatch_async(dispatch_get_main_queue(), ^{
202-
[RCTPresentedViewController() presentViewController:alertController animated:animated completion:completion]; // [TODO(macOS GH#774) When using Scenes, we must present the alert from a view controller associated with a window in the Scene
202+
[alertController show:YES completion:nil];
203203
});
204204
#else // [TODO(macOS GH#774)
205205

0 commit comments

Comments
 (0)