Tuba Kesten
01/23/2021, 4:45 PM@Composable
Outer() {
profileResult = viewmodel.field.observeAsState()
Inner(profileResult)
}
@Composable
Inner(myProfileResult: ProfileResult){
NavHost(
navController = editProfileNavController,
startDestination = EditProfileScreen.EditProfile
) {
Timber.d("profileResult1 ${myProfileResult.workEducationItems}")
composable(EditProfileScreen.EditProfile) {
Timber.d("profileResult2 ${myProfileResult.workEducationItems}")
ScrollableColumn(
modifier.padding(top= 100.dp).fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally
) { ....
}
Hi guys, I have a question related to recomposition of NavHost Composable. When the data is refreshed, profileResult1
holds the new data but profileResult2
still hold the old data (even it is recomposed). Anybody has any idea why this is happening 😄 Any solution for that other than passing with Ambient 😄 Thanks!Adam Powell
01/23/2021, 5:00 PMcomposable(EditProfileScreen.EditProfile)
is never updated with the new lambda capture that contains the updated myProfileResult
. There may already be a bug filed but feel free to file a new one.@Composable
Inner(myProfileResult: ProfileResult){
val currentProfileResult by rememberUpdatedState(myProfileResult)
NavHost(
navController = editProfileNavController,
startDestination = EditProfileScreen.EditProfile
) {
Timber.d("profileResult1 ${myProfileResult.workEducationItems}")
composable(EditProfileScreen.EditProfile) {
Timber.d("profileResult2 ${currentProfileResult.workEducationItems}")
currentProfileResult
is backed by the same snapshot state object instance that is getting updated, it will recompose your edit profile screen when it changes without needing to update the composable lambda captureTuba Kesten
01/23/2021, 8:01 PMAdam Powell
01/23/2021, 8:57 PM