elye
01/19/2022, 8:48 PMderiveStateOf
not able to work together with snapshotFlow
in aiding recomposition? Separate them out seems working, but not together. The code example in https://stackoverflow.com/q/70771821/3286489Zach Klippenstein (he/him) [MOD]
01/19/2022, 11:20 PMelye
01/20/2022, 2:53 AMAlex Vanyo
01/20/2022, 2:58 AMvar count by remember { mutableStateOf(0) }
var fromSnapshot by remember { mutableStateOf(false) }
val fromDerived by remember { derivedStateOf { count > 0 } }
LaunchedEffect(Unit) {
snapshotFlow { count }.collect { fromSnapshot = it > 1 }
}
Column {
Text("Button clicked at least 1 time: $fromDerived")
Text("Button clicked at least 2 times: $fromSnapshot")
Button(onClick = { count++ }) {
Text("Increase count")
}
}
fromSnapshot
will be set to true
when the button is clicked twice, but the text won’t be updated to reflect that.Albert Chang
01/20/2022, 3:36 AMelye
01/20/2022, 3:48 AM