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.
Arkadii Ivanov
11/04/2023, 10:54 AM
The back stack can be empty, while there is always an active component.