Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract scene related logic into function in RCTAlertController
Browse files Browse the repository at this point in the history
ouabing committed Dec 31, 2022

Verified

This commit was signed with the committer’s verified signature.
snyk-bot Snyk bot
1 parent e468621 commit cb78e7e
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions React/CoreModules/RCTAlertController.m
Original file line number Diff line number Diff line change
@@ -20,18 +20,7 @@ @implementation RCTAlertController
- (UIWindow *)alertWindow
{
if (_alertWindow == nil) {

#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
_alertWindow = [self getUIWindowFromScene];

if (_alertWindow == nil) {
_alertWindow = [[UIWindow alloc] initWithFrame:RCTSharedApplication().keyWindow.bounds];
@@ -65,4 +54,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

0 comments on commit cb78e7e

Please sign in to comment.