Shakil Karim

    Shakil Karim

    1 year ago
    Hi, i using a model class like this SomeClass( var badge: MutableState<Badge?> ...... ) But when i trying to update the badge property it Recompose even if the Badge Object is same.
    Tash

    Tash

    1 year ago
    how are you updating badge?
    make sure you're updating
    badge.value
    and not the
    badge
    MutableState
    instance. might be easier to use property delegates and write it as
    var badge by mutableStateOf<Badge?>
    instead so that you can read/write to it as a regular
    var
    .
    Shakil Karim

    Shakil Karim

    1 year ago
    I'm updating it like this
    pack.badgeText = OPEN(context.getString(R.string.open))
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    Hard to debug this without seeing more code for context. Can you post the composable that’s recomposing and the code that updates that state?
    Shakil Karim

    Shakil Karim

    1 year ago
    I'm not sure it's the correct way to solve this issue, but I have now a map that has Badges and it now only recomposes the item which is change
    val packBadges = mutableStateMapOf<String,BADGE?>()
    and on the Observing side
    PackItem(
        modifier = Modifier
            .width(boxWidth)
            .padding(horizontal = 8.dp),
        entry.packName,
        entry.lections.map { it.name }.joinToString { it },
        emojiText = entry.emoji,
        coins = entry.coins,
        bagText = packBadges["${entry.lang}${entry.pacId}${entry.packOwnerId}${entry.func}"]
    ) {
        onPackSelected(entry)
        when(packBadges["${entry.lang}${entry.pacId}${entry.packOwnerId}${entry.func}"]) {
            is OPEN ->  onOpenLections()
            is GET ->  getLections()
            is COIN ->  getLectionsWithCoins(entry.coins)
        }
    }