https://kotlinlang.org logo
#compose
Title
# compose
c

chansek

02/05/2022, 3:28 AM
Copy code
open class A(
    open val a: Int,
    val b: String = "Something"
)

data class B(
    override val a: Int = 20,
    val c: Int = 30
) : A(a)
I have a composable which is dependant upon
class B
.
Copy code
@Composable
fun BCard(b: B) {
    // Compose something
}
BCard
recomposes when
a
nad
c
are changed, but not when
b
is changed. How can I solve this?
1
m

mattinger

02/06/2022, 3:41 AM
I'm not sure i get what you are asking here. Your composable depends on an instance of B, so if that's a state value, the card will recompose when you re-assign it:
Copy code
val b = remember { mutableStateOf(B()) }

BCard(b)
and then at some later point in an onClick callback or something:
Copy code
b.value = b.value.copy(a = 50)
That should trigger recomposition of your card.