ShellBackHandler

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

Handles back while enabled, ahead of the displays composed before it.

The shell's overlays, the drawer, the modal rail, the expanded player and a search query, use this rather than the activity's BackHandler, so they share the navigation event dispatcher with the displays and take priority by being registered after them.

Registration waits for the next frame. A display inside a Scaffold is composed during layout, after everything composed beside it, so a handler composed in the same pass as the display would otherwise register first and lose to it.