BackHandler

fun BackHandler(enabled: Boolean = true, onBack: () -> Unit)

An effect for handling presses of the system back button.

Calling this in your composable adds the given lambda to the OnBackPressedDispatcher of the LocalOnBackPressedDispatcher.

If this is called by nested composables, if enabled, the inner most composable will consume the call to system back and invoke its lambda. The call will continue to propagate up until it finds an enabled BackHandler.

The onBack lambda is never invoked on platforms that don't have a system back button.

Parameters

enabled

if this BackHandler should be enabled

onBack

the action invoked by pressing the system back