Tab navigation
To use the TabNavigator
you should first import cafe.adriel.voyager:voyager-tab-navigator
(see Setup).
Voyager provides a specialized navigator for tabs : the TabNavigator
.
The Tab
interface, like the Screen
, has a Content()
composable function, but also requires a TabOptions
.
Since tabs aren't usually reused, its OK to create them as object
.
The TabNavigator
unlike the Navigator
:
Don't handle back presses, because the tabs are siblings
Don't implements the Stack API, just provides a
current
property
You can use it with a Scaffold to easily create the UI for your tabs.
Like theCurrentScreen()
, you should use CurrentTab
instead of tabNavigator.current.Content()
, because it will save the Tab's subtree for you (see SaveableStateHolder).
Use the LocalTabNavigator
to get the current TabNavigator
, and current
to get and set the current tab.
Sample
Source code here.
Last updated