https://kotlinlang.org logo
#compose
Title
# compose
l

Luis Daivid

01/08/2022, 2:08 PM
I’m making an app using bottomNavigation. However, whenever I touch the bottom tab, it is recomposed and the screen is updated. When I searched the navigation document, it came out like the one below,
Copy code
By using the saveState and restoreState flags, the state and back stack of that item is correctly saved and restored as you swap between bottom navigation items.
and of course it is recomposed every time even though it is applied. What should I do?
Here is my code
Copy code
fun navigateToBottomBarRoute(route: String) {
        if (route != currentRoute) {
            navController.navigate(route) {
                launchSingleTop = true
                restoreState = true
                popUpTo(navController.graph.findStartDestination().id) {
                    saveState = true
                }
            }
        }
    }
Copy code
val appState = rememberPwwAppState()
Scaffold(
    bottomBar = {
        if (appState.shouldShowBottomBar) {
            BottomNavigation {
                appState.bottomBarTabs.forEach { screen ->
                    BottomNavigationItem(
                        selected = appState.currentRoute == screen.route,
                        label = { Text(text = screen.name) },
                        onClick = {
                            appState.navigateToBottomBarRoute(screen.route)
                        },
                        icon = {})
                }
            }
        }
    },
) { innerPaddingModifier ->
    ...
}
a

allan.conda

01/08/2022, 3:01 PM
What do you want to do?
i

Ian Lake

01/08/2022, 11:46 PM
"it is recomposed and the screen is updated." - recomposition is a normal and expected part of a Compose app. What's the problem?
8 Views