Hey Arkadii! :wave: Would this be the correct way ...
# decompose
n
Hey Arkadii! 👋 Would this be the correct way to get the previous child in the backstack to decide what action to take depending on where you come from?
Copy code
val originIndex = childStack.value.backStack.lastIndex - 1
when (val child = childStack.value.backStack[originIndex].instance) {
    is MainBloc.SomeChild -> someAction()
    ... ->
    else -> navigation.pop() //Shouldn't be the case
}
Also, would it make sense to have extensions for this in the library API?
a
Given the
childStack
is defined as
Value<ChilfStack>
, I believe you can do the following:
Copy code
val active = childStack.active.instance
val previous = childStack.backStack.lastOrNull()
Keep in mind that the
backStack
property doesn't include the active component. There is the
items
property that includes all components.
The back stack can be empty, while there is always an active component.
n
Keep in mind that the
backStack
property doesn’t include the active component.
Oh, didn’t know that one! Thanks for it 🙂
👍 1
a
Good point, I'll expand docs for ChildStack. Filed https://github.com/arkivanov/Decompose/issues/518
K 1
🦸 1
n
😅. Not the most descriptive commit, but surely sincere.
decompose intensifies 2