Skip to content

Commit

Permalink
Fix RCTAlertController not showing when using SceneDelegate on iOS 13.0+
Browse files Browse the repository at this point in the history
  • Loading branch information
ouabing committed Dec 25, 2022
1 parent 874881e commit e468621
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion React/CoreModules/RCTAlertController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,23 @@ @implementation RCTAlertController
- (UIWindow *)alertWindow
{
if (_alertWindow == nil) {
_alertWindow = [[UIWindow alloc] initWithFrame:RCTSharedApplication().keyWindow.bounds];

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
if (@available(iOS 13.0, *)) {
for (UIScene *scene in RCTSharedApplication().connectedScenes) {
if (scene.activationState == UISceneActivationStateForegroundActive && [scene isKindOfClass:[UIWindowScene class]]) {
_alertWindow = [[UIWindow alloc] initWithWindowScene:(UIWindowScene *)scene];
break;
}
}
}
#endif

if (_alertWindow == nil) {
_alertWindow = [[UIWindow alloc] initWithFrame:RCTSharedApplication().keyWindow.bounds];
}

_alertWindow.rootViewController = [UIViewController new];
_alertWindow.windowLevel = UIWindowLevelAlert + 1;
}
Expand Down

0 comments on commit e468621

Please sign in to comment.