Skip to content

Commit

Permalink
Extract scene related logic into function in RCTAlertController
Browse files Browse the repository at this point in the history
  • Loading branch information
ouabing committed Dec 31, 2022
1 parent e468621 commit 50273c0
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
Expand Up @@ -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];
Expand Down Expand Up @@ -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 50273c0

Please sign in to comment.