I’m making an app using bottomNavigation. However,...
# compose
l
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
What do you want to do?
i
"it is recomposed and the screen is updated." - recomposition is a normal and expected part of a Compose app. What's the problem?