https://kotlinlang.org logo
Title
m

Mehdi Haghgoo

06/04/2022, 3:30 PM
val multiSelectionEnabled = rememberSaveable{mutableStateOf(selection.isNotEmpty())}.value
Will changing selection, trigger a recomposition? Can this be used instead of using delegates?
s

ste

06/04/2022, 3:34 PM
No. You need to set
selection
as a key:
var multiSelectionEnabled by rememberSaveable(selection) { mutableStateOf(selection.isNotEmpty()) }
But, unless you need to change
multiSelectionEnabled
manually, neither
rememberSaveable
nor
mutableStateOf
is needed here (that
.value
is what makes me think you are missing something)
1
z

Zach Klippenstein (he/him) [MOD]

06/06/2022, 12:48 AM
What is
selection
? If it's a snapshot state then this seems like a good use for
derivedStateOf
1
m

Mehdi Haghgoo

06/06/2022, 6:10 AM
@Zach Klippenstein (he/him) [MOD] it's not a snapshot state. İt's just an array of selections passed to composables that need it