Recomposition will happen only when you change the list itself. mutableStateListOf can only notify about adding, removing, or replacing some element in the list.
Reference: Android Jetpack Compose mutableStateListOf not doing Recomposition
Based on the preceding assumption, recomposition should be triggered on a like() method call in below code, and it was happening previously. But since I have updated versions in my code, recomposition is not triggering on a like() method call.
I am using below versions in my project and some other library versions I updated:-
val compilesdk = 33
val minsdk = 21
val targetsdk = 33
val kotlin = "1.7.20"
val compose_compiler = "1.4.0"
val compose_ui = "1.3.3"
val compose_runtime = "1.3.3"
val compose_foundation = "1.3.1"
val compose_material = "1.3.1"
ViewModel
val recipes = mutableStateListOf<Recipe>()
fun like(index: Int, likes: ArrayList<String>) {
recipes[index] = recipes[index].copy(likes = likes)
}
Composables
SocialNetworkContent(
viewModel.recipes,...
)
@Composable
fun SocialNetworkContent(
recipes: List<Recipe>,
...
){
..
items(
count = recipes.size,
itemContent = {
SocialListItem(
recipe = recipes[it],
it,
sharedPreferences,
viewModel,
onNavigateToRecipeDetailScreen,
onNavigateToUserProfileScreen
)
},
)
..
}