Replies: 2 comments 9 replies
-
Thanks for raising the idea! I already looked at Appyx. Decompose is designed differently in many ways. As you mentioned, Decompose is multiplatform and doesn't depend on Compose. So the navigation state has to be fully exposed to the UI. This makes it possible to plug any UI externally. But on the other hand, things like transitions and UI state restoration also have to be handled externally, Decompose Core can't do it for you. So the outcome here is that there must be a complete navigation state exposed from components - e.g. (Not only) because of that, Decompose goes in another direction. It is based around the concept of ComponentContext, and different navigation models are provided via extension functions like |
Beta Was this translation helpful? Give feedback.
-
I've been playing with various APIs and for now I have the following in mind. It seems working for Child Stack and Child Overlay, and also flexible enough for custom implementations. What do you think? The idea is to have The navigation is performed by transforming old I also created a draft implementation. The existing integration tests for interface NavigationSource<out T : Any> {
fun subscribe(observer: (T) -> Unit)
fun unsubscribe(observer: (T) -> Unit)
}
interface NavState<out C : Any> {
val children: List<ChildNavState<C>>
}
interface ChildNavState<out C : Any> {
val configuration: C
val status: Status
enum class Status {
DESTROYED,
INACTIVE,
ACTIVE,
}
}
// C - type of configuration
// T - type of child components
// E - type of navigation event
// N - type of custom nav state, implements NavState
// S - type of custom resulting state
// All functions are supposed to be stateless and without side effects
fun <C : Any, T : Any, E : Any, N : NavState<C>, S : Any> ComponentContext.children(
source: NavigationSource<E>,
key: String,
initialNavState: () -> N, // Returns initial NavState, called when there is no saved state
saveNavState: (navState: N) -> ParcelableContainer, // Saves the NavState into ParcelableContainer
restoreNavState: (container: ParcelableContainer) -> N, // Restores the NavState from ParcelableContainer
navTransformer: (navState: N, event: E) -> N, // Transforms old NavState to a new one by the provided navigation event
onEventComplete: (event: E, newNavState: N, oldNavState: N) -> Unit, // Called after the navigation event is handled
backTransformer: (navState: N) -> (() -> N)?, // Called after each navigation event, returns a transformer from old NavState to a new one on back press, or null not allowed
stateMapper: (navState: N, children: List<Child<C, T>>) -> S, // Returns a new state based on new NavState
childFactory: (configuration: C, componentContext: ComponentContext) -> T,
): Value<S> |
Beta Was this translation helpful? Give feedback.
-
Hi, Arkadii.
First of all, thank you for the great library. It saved hundreds of hours for us.
I like that Decompose components are independent from UI. I don't know another libraries with this feature.
Recently I found out a library called appyx - https://bumble-tech.github.io/appyx/
It is tied to Jetpack Compose, so it is not suitable for KMM apps. But there is one killer feature. Appyx has a concept called navigation model. Any type of navigation is based on it. There are build in navigation models. And it is easy to create a custom one. Take a look, please - https://bumble-tech.github.io/appyx/navigation/model-driven-navigation/
I also had watched a video about it https://www.droidcon.com/2022/09/29/model-driven-navigation-with-jetpack-compose-from-zero-to-hero/ and I am very impressed.
So, i'm wondering do you plan to make some generic mechanism for navigation in Decompose? Decompose has a child stack and a child overlay, but it is non-trivial to create something custom such as a view pager and other examples from Appyx.
Beta Was this translation helpful? Give feedback.
All reactions