in the back handling section, I would assume if my...
# decompose
a
in the back handling section, I would assume if my
BackCallback
didn't do anything, then the back would do nothing, the UI wouldn't go back. is that correct?
Copy code
private val backCallback = BackCallback { /* do nothing */ }
also I see it is applied in
init
, but I would expect to need to unregister it in a lifecycle callback, is that not needed?
basically I'm trying to prevent the back action in certain cases
ah, I think it's due to other back handlers being registered
hhmmm... so i was unregistering a backhandler in
onStop
for a component that was getting pushed on top of in a stack. But that doesnt appear to be getting called. Are components lower down in a stack (not active) to be considered "started"?
a
Unfortunately, due to the way the predictive back gesture works on Android, it's not possible to intercept the back button press. This was the case a while ago, when the back handler was returning a boolean. But I had to align the API with the AndroidX
OnBackPressedDispatcher
. So you have to update the callback's
isEnabled
property according to your state.
a
okay, so updating that state as things change, not when a back event is propagating?
way to make things more difficult google 😛 but thats fine
the next thing here is the started/resumed state though, this seems off to me
a
Yeah! Turned out there are technical limitations on Android. There was an interesting conversation about it which explains everything https://twitter.com/ianhlake/status/1553433732329009152
a
oh, nvm
I think i discovered my state issue here
but last question, do I really not need to worry about calling
unregister
ever?
a
Usually you don't. It's the same as unsubscribing from Lifecycle.
a
ah okay
what I've been digging around the edges of here, is that the backhandler in
Comp A
always fires, but never the backhandler in
Comp B
. Maybe the order of operations I'm expecting is different? I would expect a bottom up propagation, so a child could steal the event first.
a
That's because the component's BackHandler has the same scope as the component itself.
a
if both handlers are enabled that is
a
By default, back callbacks are called in reverse order. If you register a callback after creating your Child Stack, it has higher priority. Starting with Essenty 1.2.x alpha, you can specify a priority for your callback.
a
oohhh
up that was it, my init block doing the registering was lower down in the file than my call to
componentContext._childStack()_
thanks !
a
Perhaps, it would be nice to have this documented. I will add this.
a
looks great, thanks!