Hi. Trying to migrate from `back-pressed` to `back...
# decompose
x
Hi. Trying to migrate from
back-pressed
to
back-handler
api to enable predictive back for
jetbrains-compose
with the new
StackNavigation
. Previously (as of 0.6.0) we had to do
Copy code
val LocalBackPressedHandler: ProvidableCompositionLocal<BackPressedHandler?> = staticCompositionLocalOf { null }

// On activity
val backPressedHandler = BackPressedHandler(onBackPressedDispatcher)

setContent {
  CompositionLocalProvider(LocalBackPressedHandler provides backPressedHandler) {
    ..
  }
}
is this no longer necessary given the
ChildStack
has a
handleBackButton
?
a
In the previous version of that article, ComoinentContext was created manually with all arguments supplied into it, including the back handler. In the new version, the whole ComponentContext is created in the activity using
defaultComponentContext
extension function and is propagated via Locals. Yes, you can just pass
handleBackButton = true
argument and Child Stack will automatically pop screens on back presses.
x
Nice 👍 working as expected
a
Looks nice!