Navigation
To use the Navigator
you should first import cafe.adriel.voyager:voyager-navigator
(see Setup).
Screen
On Voyager, screens are just classes with a composable function as the entrypoint. To create one, you should implement the Screen
interface and override the Content()
composable function.
You can use data class
(if you need to send params), class
(if no param is required) or even object
(useful for tabs).
Navigator
Navigator
is a composable function deeply integrated with Compose internals. It'll manage the lifecyle, back press, state restoration and even nested navigation for you.
To start using it, just set the initial Screen
.
Use the LocalNavigator
to navigate to other screens. Take a look at the Stack API for the available operations.
If part of your UI is shared between screens, like the TopAppBar
or BottomNavigation
, you can easily reuse them with Voyager.
You should use CurrentScreen()
instead of navigator.lastItem.Content()
, because it will save the Screen's subtree for you (see SaveableStateHolder).
Sample
Source code here.
Last updated