rememberNavigationEventDispatcherOwner

Functions summary

NavigationEventDispatcherOwner

Remembers a new NavigationEventDispatcherOwner which creates a dispatcher linked to a parent dispatcher found in the composition.

Cmn

Functions

rememberNavigationEventDispatcherOwner

@Composable
fun rememberNavigationEventDispatcherOwner(
    enabled: Boolean = true,
    parent: NavigationEventDispatcherOwner? = checkNotNull(LocalNavigationEventDispatcherOwner.current) { "No NavigationEventDispatcherOwner provided in LocalNavigationEventDispatcherOwner. " + "If you intended to create a root dispatcher, explicitly pass null as the parent." }
): NavigationEventDispatcherOwner

Remembers a new NavigationEventDispatcherOwner which creates a dispatcher linked to a parent dispatcher found in the composition.

This composable creates a dispatcher that links to any parent dispatcher found in the composition, forming a parent-child relationship. If no parent exists, it automatically becomes a new root dispatcher, this is the top-most parent in a hierarchy. This is useful for isolating navigation handling within specific UI sections, such as a self-contained feature screen or tab.

The dispatcher's lifecycle is automatically managed. It is created only once and automatically disposed of when the composable leaves the composition, preventing memory leaks.

When used to create a root dispatcher, you must use a NavigationEventInput to send it events. Otherwise, the dispatcher will be detached and will not receive events.

To provide the new NavigationEventDispatcherOwner to a sub-composition, use androidx.compose.runtime.CompositionLocalProvider:

androidx.navigationevent.compose.samples.RememberNavigationEventDispatcherOwner

Null parent: If parent is EXPLICITLY null, this creates a root dispatcher that runs independently. By default, it requires a parent from the LocalNavigationEventDispatcherOwner and will throw an IllegalStateException if one is not present.

Parameters
enabled: Boolean = true

Controls if the dispatcher is active. If this value changes, the dispatcher's isEnabled property will be updated. When false, this dispatcher and any of its children will not receive events. Defaults to true.

parent: NavigationEventDispatcherOwner? = checkNotNull(LocalNavigationEventDispatcherOwner.current) { "No NavigationEventDispatcherOwner provided in LocalNavigationEventDispatcherOwner. " + "If you intended to create a root dispatcher, explicitly pass null as the parent." }

The NavigationEventDispatcherOwner to use as the parent, or null if it is a root. Defaults to the owner from LocalNavigationEventDispatcherOwner.

Returns
NavigationEventDispatcherOwner

A new NavigationEventDispatcherOwner that is remembered across compositions.