Is there something like `onBackPressed` listener? ...
# compose
s
Is there something like
onBackPressed
listener? I want to override onBackPressed to make sure I don't navigate back in certain cases
g
Modifier.keyInputFilter
a
Key input is subject to various key event dispatch and focus rules that can cause the events to be missed. The androidx OnBackPressedDispatcher is the preferred way of doing it these days; if you poke around the jet* samples you can see a few copy/pastes of basically this gist: https://gist.github.com/adamp/62d13fe5bf0d6ddf9fcf58f8a6769523
👌 1
the style in there is a bit dated but you get the idea 🙂 use
Providers
up near your initial
setContent
or whatnot to provide the OnBackPressedDispatcherOwner and you're good to go
s
Got it. Thanks!
AmbientBackPressedDispatcher
isn't supposed to be private right?
a
Up to you. I pulled this out of an app I was writing where it was in the same file I was providing it from 🙂
🙏 1