0

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
                    )
                },
            )
..
}
Android Developer
  • 9,157
  • 18
  • 82
  • 139
  • 1
    Is `Recipe` a data class, or does it have an `equals` that includes `likes` in its comparison? If not, then there would be no way for the list to detect that anything has been changed. – Tenfour04 Mar 01 '23 at 16:17
  • @Tenfour04 Recipe is a data class and it has equals implementation that included likes in its comparison `if (likes != other.likes) return false` – Android Developer Mar 01 '23 at 16:47

0 Answers0