Hi, recently I was investigating Navigation3 and I...
# decompose
c
Hi, recently I was investigating Navigation3 and I immediately liked the idea where the user kept the single-source-of-truth. This brings the idea where I can use MVIKotlin to store my navigation state and have Navigation3 automatically update based on my store. I am wondering do we have any plan to add similar functionality in Decompose, or is it possible to replicate Navigation3 with the Decompose current Generic Navigation?
a
There is a doc on generic navigation you might want to check out https://arkivanov.github.io/Decompose/navigation/children/overview/
👍 1
a
In its core, Decompose is all based around manipulating child insurances of ComponentContext. You can do it manually, but it might not be trivial. The Generic Navigation (as well as all other predefined navigation models) own (host) the navigation state. The state is manipulated via navigation events – a pure function from the old state to a new one. You can host your state somewhere else, but with predefined navigation models you will need to feed that state to Decompose: it will store a reference to it and perform the navigation as needed.
I.e. you can map your StateFlow<State> to NavigationSource<nav_event> and pass to the navigation model via the
source
argument.
👍 2
c
Yeah, I guess we can just create an Event class that simply just warps a state. And for
navTransform: (state: N, event: E) -> N
, we simply just replace the whole state with the new state from the event.
Then we call
.navigate(myNewEventThatHoldNewState)
in the
StateFlow<State>
collect function
a
Yep, this should work.
👍 1