What does Jetpack Compose remember actually do, how does it work under the hood?

remember – allows you to remember state from previous recompose invocation and just this. So, if you for instance randomize color at initial run. The randomized color is going to be calculated only once and later reused whenever re-compose is necessary. And hence, remember = store the value just in case recompose is called. Now, … Read more

Jetpack Compose Navigation loads screen infinitely

I re-implemented your posted code with 2 screens, HomeScreen and SettingScreen and stripped out some part of the UiState class and its usages. The issue is in your HomeScreen composable, not in the StateFlow emission. You have this mutableState val uiState by viewModel.uiState.collectAsStateWithLifecycle( initialValue = UiState.Speak ) that is being observed in one of your … Read more

Jetpack Compose lazy column all items recomposes when a single item update

MutableState works using structural equality which check if you update state.value with new instance. You are creating a new instance of your list on each time you select a new item. You can use SnapshotStateList which triggers recomposition when you add, delete or update existing item with new instance. SnapshotStateList is a List which gets … Read more

Jetpack Compose Smart Recomposition

To have smart recomposition scopes play a pivotal role. You can check Vinay Gaba’s What is “donut-hole skipping” in Jetpack Compose? article. Leland Richardson explains in this tweet as The part that is “donut hole skipping” is the fact that a new lambda being passed into a composable (ie Button) can recompose without recompiling the … Read more