Skip to content

Commit 42ceacd

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Fallback to the first foregroundInactive window when there are no foregroundActive windows in RCTKeyWindow (facebook#44167)
Summary: Pull Request resolved: facebook#44167 We received an issue for OSS where, when the main window is inactive and the system tries to present a dialog, the dialog is not presented in the right position on the screen. This change introduce a fallback to the first inactive window (which is still visible on screen) and it fixes the issues. ## Changelog: [iOS][Changed] - Fallback to the first `foregroundInactive` window when there are no `foregroundActive` windows in RCTKeyWindow Reviewed By: dmytrorykun Differential Revision: D56354741 fbshipit-source-id: fa23131ecd40f6d91c705879a72890506ee21486
1 parent c402dcf commit 42ceacd

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

packages/react-native/React/Base/RCTUtils.m

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -562,21 +562,37 @@ BOOL RCTRunningInAppExtension(void)
562562
return nil;
563563
}
564564

565-
for (UIScene *scene in RCTSharedApplication().connectedScenes) {
566-
if (scene.activationState != UISceneActivationStateForegroundActive ||
567-
![scene isKindOfClass:[UIWindowScene class]]) {
565+
NSSet<UIScene *> *connectedScenes = RCTSharedApplication().connectedScenes;
566+
567+
UIScene *foregroundActiveScene;
568+
UIScene *foregroundInactiveScene;
569+
570+
for (UIScene *scene in connectedScenes) {
571+
if (![scene isKindOfClass:[UIWindowScene class]]) {
568572
continue;
569573
}
570-
UIWindowScene *windowScene = (UIWindowScene *)scene;
571574

572-
if (@available(iOS 15.0, *)) {
573-
return windowScene.keyWindow;
575+
if (scene.activationState == UISceneActivationStateForegroundActive) {
576+
foregroundActiveScene = scene;
577+
break;
574578
}
575579

576-
for (UIWindow *window in windowScene.windows) {
577-
if (window.isKeyWindow) {
578-
return window;
579-
}
580+
if (!foregroundInactiveScene && scene.activationState == UISceneActivationStateForegroundInactive) {
581+
foregroundInactiveScene = scene;
582+
// no break, we can have the active scene later in the set.
583+
}
584+
}
585+
586+
UIScene *sceneToUse = foregroundActiveScene ? foregroundActiveScene : foregroundInactiveScene;
587+
UIWindowScene *windowScene = (UIWindowScene *)sceneToUse;
588+
589+
if (@available(iOS 15.0, *)) {
590+
return windowScene.keyWindow;
591+
}
592+
593+
for (UIWindow *window in windowScene.windows) {
594+
if (window.isKeyWindow) {
595+
return window;
580596
}
581597
}
582598

0 commit comments

Comments
 (0)