From 63eeab6539956a781035df82b29b7550f4404635 Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Mon, 7 Oct 2024 13:33:52 -0700 Subject: [PATCH] Fix for multi-root apps with Modal Summary: In multi-root Android React Native apps (e.g., multiple ReactFragments), if the following sequence occurs: 1. a Modal is displayed via the secondary root 2. the secondary root is destroyed 3. the app is backgrounded 4. the app is foregrounded The LifecycleEventListener on the ReactModalHostView will fire, causing the Modal to be rehydrated in the onHostResume callback. Removing the lifecycle event listener when the modal is detached from the window resolves the issue. ## Changelog [Android][Fix] Fix issues with Modals and lifecycle events in multi-surface apps Differential Revision: D64001103 --- .../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 f61fa85d7b8103..5de736128e5040 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 @@ -133,7 +133,7 @@ public class ReactModalHostView(context: ThemedReactContext) : protected override fun onDetachedFromWindow() { super.onDetachedFromWindow() - dismiss() + onDropInstance() } public override fun addView(child: View?, index: Int) {