Material design modal wide navigation rail.
ModalWideNavigationRailSample
@Preview
@Sampled
@Composable
fun ModalWideNavigationRailSample() {
var selectedItem by rememberSaveable { mutableIntStateOf(0) }
val items = listOf("Home", "Search", "Settings")
val selectedIcons = listOf(Icons.Filled.Home, Icons.Filled.Favorite, Icons.Filled.Star)
val unselectedIcons =
listOf(Icons.Outlined.Home, Icons.Outlined.FavoriteBorder, Icons.Outlined.StarBorder)
val state = rememberWideNavigationRailState()
val scope = rememberCoroutineScope()
val headerDescription =
if (state.targetValue == WideNavigationRailValue.Expanded) {
"Collapse rail"
} else {
"Expand rail"
}
Row(Modifier.fillMaxWidth()) {
ModalWideNavigationRail(
state = state,
// Note: the value of expandedHeaderTopPadding depends on the layout of your screen in
// order to achieve the best alignment.
expandedHeaderTopPadding = 64.dp,
header = {
// Header icon button should have a tooltip.
DismissibleModalWideNavigationRailSample
@Preview
@Sampled
@Composable
fun DismissibleModalWideNavigationRailSample() {
var selectedItem by rememberSaveable { mutableIntStateOf(0) }
val items = listOf("Home", "Search", "Settings")
val selectedIcons = listOf(Icons.Filled.Home, Icons.Filled.Favorite, Icons.Filled.Star)
val unselectedIcons =
listOf(Icons.Outlined.Home, Icons.Outlined.FavoriteBorder, Icons.Outlined.StarBorder)
val state = rememberWideNavigationRailState()
val scope = rememberCoroutineScope()
Row(Modifier.fillMaxSize()) {
ModalWideNavigationRail(state = state, hideOnCollapse = true) {
items.forEachIndexed { index, item ->
WideNavigationRailItem(
railExpanded = true,
icon = {
Icon(
if (selectedItem == index) selectedIcons[index]
else unselectedIcons[index],
contentDescription = null,
)
},
label = { Text(item) },
selected = selectedItem == index,
onClick = {
selectedItem = index
scope.launch { state.collapse() }
},
)
}
}
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
val currentPage = items.get(selectedItem)
Button(onClick = { scope.launch { state.expand() } }, Modifier.padding(32.dp)) {
Text(text = "$currentPage Page\nOpen modal rail", textAlign = TextAlign.Center)
}
}
}
}