Skip to content

Commit

Permalink
Fix for multi-root apps with Modal (facebook#46867)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rozele authored and facebook-github-bot committed Oct 7, 2024
1 parent 86d92e4 commit 2427589
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public class ReactModalHostView(context: ThemedReactContext) :
private var createNewDialog = false

init {
context.addLifecycleEventListener(this)
dialogRootViewGroup = DialogRootViewGroup(context)
}

Expand All @@ -131,9 +130,14 @@ public class ReactModalHostView(context: ThemedReactContext) :
dialogRootViewGroup.id = id
}

protected override fun onAttachedToWindow() {
super.onAttachedToWindow()
(context as ThemedReactContext).addLifecycleEventListener(this)
}

protected override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
dismiss()
onDropInstance()
}

public override fun addView(child: View?, index: Int) {
Expand Down

0 comments on commit 2427589

Please sign in to comment.