John Aoussou
03/19/2022, 2:09 PM@Composable
fun App() {
var myClass = remember { MyClass() }
MaterialTheme {
Column() {
Text(text="${myClass.myInt.value}")
Button(onClick = myClass::run){ Text(text = "RUN") }
}
}
}
where
class MyClass {
val myInt = mutableStateOf(0)
fun run(){
for (i in 0..10){
myInt.value = i
Thread.sleep(500)
}
}
}
what am I missing?Arsen
03/19/2022, 2:56 PMval stateOfInt: State<Int> = produceState(0) {
var result = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
delay(1000)
1
}
value = result
result = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
delay(1000)
2
}
value = result
}
P.S. example above is "serial", second block will start when first one finish, to make it "parallel" wrap each block with "launch { }"John Aoussou
03/19/2022, 8:58 PMArsen
03/20/2022, 11:42 AMZach Klippenstein (he/him) [MOD]
03/20/2022, 4:23 PMwithFrameMillis
instead of delay, if not one of the higher level apis.