Sam Stone
07/10/2023, 12:54 AM@Compose
fun Parent() {
var updatingValue by remember { mutableStateOf(0) }
LaunchedEffect(Unit) {
while(isActive) {
delay(1_000)
updatingValue += 1
}
}
repeat(10) { Child(updatingValue) }
}
@Compose
fun Child(updatingValue: Int) {
Text(updatingValue.toString())
}
B:
@Compose
fun Parent() {
repeat(10) { Child() }
}
@Compose
fun Child() {
var updatingValue by remember { mutableStateOf(0) }
LaunchedEffect(Unit) {
while(isActive) {
delay(1_000)
updatingValue += 1
}
}
Text(updatingValue.toString())
}
Francesc
07/10/2023, 12:56 AMephemient
07/10/2023, 1:02 AMRob
07/10/2023, 1:43 AMSam Stone
07/10/2023, 11:25 AMRob
07/10/2023, 8:49 PMMutableStateFlow<Int>
in your Android ViewModel. Expose immutable StateFlow<Int>
using asStateFlow()
. Observe the StateFlow<Int>
using collectAsStateWithLifecycle()
at beginning of setContent
of ComposeView and only send immutable data to Composables. Update the ViewModel state by sending events to the ViewModel.Rob
07/10/2023, 8:55 PM