From eaa780de1c799bf35fded2914d27b1953b093340 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Tue, 1 Oct 2024 10:59:40 -0700 Subject: [PATCH] Fix crash for Modal not attached to window manager (#46758) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46758 There are some occurrencies where the Modal results not attached to the Window, perhaps when the app is backgrounded. This trigger an exception `java.lang.IllegalArgumentException: View=DecorView@b9f88af[AdsManagerActivity] not attached to window manager`.\ This was fixed already but the conversion from Java to Kotlin missed a condition in the `||` clause. We are adding it back. ## Changelog [Android][Fixed] - Fix crash for Modal not attached to window manager ## Facebook The original fix is in this diff D22264672 by mdvacca Also see this post: https://fb.workplace.com/groups/rn.support/permalink/27047414764880449/ Reviewed By: cortinico Differential Revision: D63700769 fbshipit-source-id: bc8a44868d5cacb8822e1646c2b7643682f45e1b --- .../java/com/facebook/react/views/modal/ReactModalHostView.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt index 316efcd44b1..e784ec3ed17 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt @@ -306,7 +306,7 @@ public class ReactModalHostView(context: ThemedReactContext) : val dialogWindow = checkNotNull(dialog.window) { "dialog must have window when we call updateProperties" } val currentActivity = getCurrentActivity() - if (currentActivity == null || currentActivity.isFinishing) { + if (currentActivity == null || currentActivity.isFinishing || !dialogWindow.isActive) { // If the activity has disappeared, then we shouldn't update the window associated to the // Dialog. return