androidx.navigationevent.compose

Objects

LocalNavigationEventDispatcherOwner

The CompositionLocal containing the current NavigationEventDispatcher.

Cmn

Top-level functions summary

Unit
@Composable
NavigationEventHandler(
    enabled: () -> Boolean,
    onEvent: suspend (progress: Flow<NavigationEvent>) -> Unit
)

Handles predictive back navigation gestures.

Cmn

Top-level functions

@Composable
fun NavigationEventHandler(
    enabled: () -> Boolean = { true },
    onEvent: suspend (progress: Flow<NavigationEvent>) -> Unit
): Unit

Handles predictive back navigation gestures.

This effect registers a handler with the NavigationEventDispatcher provided by the LocalNavigationEventDispatcherOwner. The handler receives updates on the progress of system back gestures as a Flow of NavigationEvent.

Use it as follows:

NavigationEventHandler { progress: Flow<NavigationEvent> ->
// This block is executed when the back gesture begins.
try {
progress.collect { backEvent ->
// Handle gesture progress updates here.
}
// This block is executed if the gesture completes successfully.
} finally {
// This block is executed if the gesture is cancelled.
}
}

When multiple NavigationEventHandler are present, only the innermost enabled handler will receive the gesture events. If no handlers are enabled, the event will propagate up the hierarchy.

Parameters
enabled: () -> Boolean = { true }

Set to false to disable this handler. Defaults to true.

onEvent: suspend (progress: Flow<NavigationEvent>) -> Unit

The lambda that receives the flow of back gesture events.