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

Arkadii Ivanov

08/05/2022, 12:33 PM
Decompose 1.0.0-alpha-01 is released! - Version updated: Kotlin 1.7.0, Gradle 7.4.2, JB Compose 1.2.0-alpha01-dev753, Jetpack Compose 1.2.0 - Replaced BackPressedHandler with BackHandler - Added otherChild argument to stackAnimation selector function - Removed previously deprecated Router And more! Release notes: https://github.com/arkivanov/Decompose/releases/tag/1.0.0-alpha-01
🎉 7
K 4
x

xxfast

08/08/2022, 3:06 AM
With the
Router<C,V>
gone, does it mean we have to write our own one in order to do our own decompose navigator?
a

Arkadii Ivanov

08/08/2022, 9:30 AM
Thanks for pointing it out. I think the approach should be changed as well. Something like
fun rememberNavigation(): StackNavigation
and
fun rememberChildStack(navigation, ...): Value<ChildStack>
or you can define your own Router interface around these two. I will update articles, filed https://github.com/arkivanov/Decompose/issues/173
But you definitely don't have to write your own Router. The Router had one method
navigate
and
state
property. It is now split by
StackNavigation
and just
Value<ChildStack>
l

Laurence Muller

08/23/2022, 6:46 PM
x

xxfast

11/19/2022, 1:47 AM
Hi all - finally got around to this (after 3 months) but I'm quite confused as to how to connect these two pieces together 🤔
Copy code
@Composable
fun <C: Parcelable> rememberNavigator(): StackNavigation<C> = remember { StackNavigation() }

@Composable
fun <C: Parcelable> rememberChildStack(root: C): ChildStack<C, Unit> = remember { ChildStack(root, Unit) }
My intended use site looks like this
Copy code
@OptIn(ExperimentalDecomposeApi::class)
@Composable
fun RootView() {
  val childStack: ChildStack<RootNavigationPage, Unit> = rememberChildStack(Search)
  val navigator: StackNavigation<RootNavigationPage> = rememberNavigator()

  Children(
    stack = childStack
  ) { (state) ->
    when (state) {
      Search -> SearchRootView()
      Settings -> SettingsView()
      else -> {}
    }
  }
}
a

Arkadii Ivanov

11/19/2022, 9:06 AM
Why do you need to remember ChildStack? It should be observable I guess, e.g. it should be Value or State
x

xxfast

11/20/2022, 3:39 AM
Nice 👍 thanks @Arkadii Ivanov. This helps me out a lot. Got a couple more questions. Is there a way to expose the current active configuration from the navigator? With previous router API i was able to do
Copy code
routerState.activeChild.configuration
Also - with the new API, it looks like it no longer retains state between transitions 🤔 Not sure If i implemented this wrong. Let me verify if this is the case with compose navigator example
Hmm the example does seem to work as intended - i definitely stuffed-up somewhere 😅
a

Arkadii Ivanov

11/20/2022, 9:08 AM
ComonentConext#childStack
function returns
Value<ChildStack>
, which provides you access to the state.
x

xxfast

11/20/2022, 9:49 PM
ah looks like my bottom nav usecase calls for something like
navigateSingleTop
rather than
bringToFront
🤔 Looks like this was already discussed in the past but the links in the discussion seems broken - but tracing back to this issue, i'm assuming this is not kept in the library due to enum support?
a

Arkadii Ivanov

11/20/2022, 9:51 PM
bringToFront
is just another name for
navigateSingleTop
. The latter naming was just suggested in that discussion, but the actual API got the former naming.
x

xxfast

11/20/2022, 10:02 PM
We should be able to use a
StackNavigator
for a bottom navigation use case with
bringToFront
, right?
Turns out changing my configuration type from enum to a sealed interface seems to make
bringToFront
behave correctly. Not 100% sure why
Anyways its now fixed 🙌 Thanks @Arkadii Ivanov
a

Arkadii Ivanov

11/20/2022, 11:04 PM
Yes,
bringToFront
should be usable in bottom navigation. Also enums as configurations shouldn't be used. Basically they won't even compile for Android, but I guess you don't support Android.
bringToFront
removes all configurations with of the specified configuration class, and adds a new configuration at the top of the stack - see the docs. Since enum entries share the same class, the stack is cleared on every navigation.
6 Views