David Dupraz
06/23/2021, 1:25 PMIgor Demin
06/23/2021, 1:36 PMgetHandCards(game)
just game.handCards
.
Composable that uses this state should be recomposed automatically, no need in callbacks.mutableListOfI misread the code 🙂 . If you use
mutableStateListOf
in your state instead of that, Composable will be recomposed automatically.@Composable
fun getPlayerRowCards(game: Game): State<MutableList<PlayCard>>{
var cards = remember { mutableStateOf(game.playerRowCards) }
DisposableEffect(game) {
val callback =
object : GameCallback {
override fun onNewCard() {
cards.value=game.playerRowCards
}
}
game.registerToPlayerRow(callback)
onDispose { game.unregisterToPlayerRow(callback) }
}
return cards
}
David Dupraz
06/23/2021, 2:56 PMMichael Paus
06/24/2021, 7:24 AM