Modo Overview
Here's the improved version of your documentation text:
Modo is a simple and convenient state-based navigation library for Jetpack Compose. It offers a flexible and powerful way to manage navigation in your application.
The UI of Modo navigation is defined by
NavigationState
, which is a structure ofScreen
andContainerScreen
. You can easily modifyNavigationState
to suit your needs from any part of your application.
Main Idea
Navigation is a Graph
Each integration of Modo is a rooted tree (wiki) that can be displayed as follows:
Each node is a
Screen
orContainerScreen
.Leaf nodes are
Screen
s.Inner nodes are
ContainerScreen
s. They can contain otherScreen
s orContainerScreen
s in theirnavigationState
.The root node is a
RootScreen
. You can have multiple roots in your app. See How to integrate Modo for details.
Convenient Navigation
Modo is an easy-to-use library. Here are some of the most-used features of Modo navigation:
Screen
is the basic unit of the UI. It displays content defined in the overriddenfun Content(modifier: Modifier)
.@Parcelize class SampleScreen( override val screenKey: ScreenKey = generateScreenKey() ) : Screen { @Composable override fun Content(modifier: Modifier) { Text( text = "Hello, Modo! Screen №$screenIndex", modifier = modifier ) } }To navigate between screens in a stack, simply call
forward()
andback()
onStackScreen
, which is an implementation ofContainerScreen
.// 1. Taking the nearest stack screen val stackNavigation = LocalStackNavigation.current // 2. Performing navigation val onForwardClick = { stackNavigation.forward(SampleScreen()) }You can easily change
NavigationState
as needed by callingdispatch(action: (StackState) -> StackState)
onNavigationContainer
:navigation.dispatch { oldState -> StackState( oldState.stack.filterIndexed { index, screen -> index % 2 == 0 && screen != oldState.stack.last() } ) }To integrate Modo with your application, use
rememberRootScreen
inside aFragment
orActivity
. You can useDefaultStackScreen
as a default stack implementation.setContent { val rootScreen = rememberRootScreen { DefaultStackScreen(SampleScreen()) } rootScreen.Content(Modifier.fillMaxSize()) }
Getting Started
To get started with Modo, check out our Quick Start Guide and explore the sample application to see how Modo can simplify your navigation needs.