Closed wying111 closed 3 months ago
Thanks for the question. I think there is no any nice way of doing this. I will think about it. For now you can try registering a back callback in that component for which you want to disable the back gesture.
class B(
componentContext: ComponentContext,
onFinished: () -> Unit,
) : ComponentContext by componentContext {
init {
backHandler.register(BackCallback(onBack = onFinished))
}
}
Then in the parent component you can pass the onFinished
callback as follows:
onFinished = navigation::pop
Thank you. I'll take your advice into consideration.
Let's keep this issue open for a while. The use case is valid and I might add an API for it. Thanks!
The new version 3.2.0-alpha05 features some improvements to the new experimental animation API released earlier in version 3.2.0-alpha03
. It's possible to do something as follows.
@Composable
fun RootContent(component: Root) {
ChildStack(
stack = component.stack,
animation = stackAnimation(
animator = fade(),
predictiveBackParams = { stack ->
if (stack.active.instance is Root.Child.ChildB) {
return@stackAnimation null
}
PredictiveBackParams(
backHandler = component.backHandler,
onBack = component::onBack,
animatable = ::materialPredictiveBackAnimatable,
)
}
)
) {
when (val child = it.instance) {
is Root.Child.ChildA -> TODO()
is Root.Child.ChildB -> TODO()
is Root.Child.ChildC -> TODO()
}
}
}
Don't forget to pass handleBackButton = true
when creating childStack
.
I have implemented Predictive Back Gesture on iOS following the code from this page: https://arkivanov.github.io/Decompose/extensions/compose/. My navigation is based on Child Stack. When I navigate from page A to page B, I want to disable the swipe-back gesture on iOS on page B. Is there a way to achieve this?