bodo
09/28/2024, 7:32 AMfun ScreenHorizontalPager() {
Timber.v("This log message gets executed twice")
val screenViewModel = viewModel<ScreenViewModel>()
screenViewModel.dispatch(action = KScreenLoadAction())
// screenViewState starts with Loading and then switches to success or error
val screenViewState by screenViewModel.state.collectAsState()
when(screenViewState) {
is Loading -> ...
is Success -> ...
is Error -> ...
}
}
romainguy
09/28/2024, 7:49 AMbodo
09/28/2024, 8:06 AMcurioustechizen
09/28/2024, 8:15 AMscreenViewState
changes the nearest scope gets recomposed. In this case it is your entire Composable function, not just the portion of it after the line where the state change happened.
You can read more about recomposition scopes here: https://developer.android.com/develop/ui/compose/performance/bestpracticesbodo
09/28/2024, 8:24 AMStylianos Gakis
09/28/2024, 9:31 AMStylianos Gakis
09/28/2024, 9:33 AMFrançois
09/28/2024, 11:54 AM