Hello i want to update page(open by navigation) on...
# compose
m
Hello i want to update page(open by navigation) on every click on BottomBar, but i don't want to reload whole page, only data in it. what is best way to do it. For now i find a way to create some mutablestate, update it and check it on Navigation destination
Copy code
val mutableState = remember { mutableStateOf(1) }
BottomNavigationItem(
...
 onClick = {
      state.value = state.value + 1
navController.navigate("home") {
    popUpTo(navController.graph.startDestinationRoute!!) {
        saveState = true
    }
    launchSingleTop = true
    restoreState = true
}
}
and one navigation destination
Copy code
fun NavGraphBuilder.HomeFeature(mutableState: MutableState<Int>){
        composableCommand(NavigationDirections.home) {
            Text(text = "HomeLayout  ${mutableState.value}")
        }
    }
i
If you're saving your data (i.e., using
rememberSaveable
) or by storing it in a ViewModel, it will already be there when you navigate to that destination with the code you have written. That would also means that it would be cleaned up correctly when you pop that destination off the back stack (which would not be the case for a hoisted
remember
variable)
m
Ok thank you :)