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 RCTAlertController not showing when using SceneDelegate on iOS 13.0+ #35716

Closed
wants to merge 2 commits into from
Closed
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
31 changes: 25 additions & 6 deletions React/CoreModules/RCTAlertController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@ @implementation RCTAlertController
- (UIWindow *)alertWindow
{
if (_alertWindow == nil) {
UIWindow *keyWindow = RCTSharedApplication().keyWindow;
if (keyWindow) {
_alertWindow = [[UIWindow alloc] initWithFrame:keyWindow.bounds];
_alertWindow = [self getUIWindowFromScene];

if (_alertWindow == nil) {
UIWindow *keyWindow = RCTSharedApplication().keyWindow;
if (keyWindow) {
_alertWindow = [[UIWindow alloc] initWithFrame:keyWindow.bounds];
} else {
// keyWindow is nil, so we cannot create and initialize _alertWindow
NSLog(@"Unable to create alert window: keyWindow is nil");
}
}

if (_alertWindow) {
_alertWindow.rootViewController = [UIViewController new];
_alertWindow.windowLevel = UIWindowLevelAlert + 1;
} else {
// keyWindow is nil, so we cannot create and initialize _alertWindow
NSLog(@"Unable to create alert window: keyWindow is nil");
}
}

Expand Down Expand Up @@ -56,4 +63,16 @@ - (void)hide
_alertWindow = nil;
}

- (UIWindow *)getUIWindowFromScene
{
if (@available(iOS 13.0, *)) {
for (UIScene *scene in RCTSharedApplication().connectedScenes) {
if (scene.activationState == UISceneActivationStateForegroundActive && [scene isKindOfClass:[UIWindowScene class]]) {
return [[UIWindow alloc] initWithWindowScene:(UIWindowScene *)scene];
}
}
}
return nil;
}

@end