https://kotlinlang.org logo
#decompose
Title
# decompose
n

Nacho Ruiz Martin

11/04/2023, 10:45 AM
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

Arkadii Ivanov

11/04/2023, 10:53 AM
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

Nacho Ruiz Martin

11/04/2023, 11:03 AM
Keep in mind that the
backStack
property doesn’t include the active component.
Oh, didn’t know that one! Thanks for it 🙂
👍 1
a

Arkadii Ivanov

11/04/2023, 11:09 AM
Good point, I'll expand docs for ChildStack. Filed https://github.com/arkivanov/Decompose/issues/518
K 1
🦸 1
n

Nacho Ruiz Martin

11/04/2023, 12:06 PM
😅. Not the most descriptive commit, but surely sincere.
decompose intensifies 2
2 Views