Avoids bottom nav recompositions
This commit is contained in:
@@ -144,25 +144,35 @@ private fun RenderBottomMenu(
|
|||||||
)
|
)
|
||||||
NavigationBar(tonalElevation = Size0dp) {
|
NavigationBar(tonalElevation = Size0dp) {
|
||||||
bottomNavigationItems.forEach { item ->
|
bottomNavigationItems.forEach { item ->
|
||||||
HasNewItemsIcon(item, accountViewModel, navEntryState, nav)
|
ObserveSelection(item, navEntryState) { selected ->
|
||||||
|
HasNewItemsIcon(selected, item, accountViewModel, nav)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun RowScope.HasNewItemsIcon(
|
private fun ObserveSelection(
|
||||||
route: Route,
|
route: Route,
|
||||||
accountViewModel: AccountViewModel,
|
|
||||||
navEntryState: State<NavBackStackEntry?>,
|
navEntryState: State<NavBackStackEntry?>,
|
||||||
nav: (Route, Boolean) -> Unit,
|
content: @Composable (Boolean) -> Unit,
|
||||||
) {
|
) {
|
||||||
val selected =
|
content(
|
||||||
navEntryState.value
|
navEntryState.value
|
||||||
?.destination
|
?.destination
|
||||||
?.route
|
?.route
|
||||||
?.startsWith(route.base) ?: false
|
?.startsWith(route.base) ?: false,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun RowScope.HasNewItemsIcon(
|
||||||
|
selected: Boolean,
|
||||||
|
route: Route,
|
||||||
|
accountViewModel: AccountViewModel,
|
||||||
|
nav: (Route, Boolean) -> Unit,
|
||||||
|
) {
|
||||||
NavigationBarItem(
|
NavigationBarItem(
|
||||||
alwaysShowLabel = false,
|
alwaysShowLabel = false,
|
||||||
icon = {
|
icon = {
|
||||||
|
|||||||
Reference in New Issue
Block a user