humbledroid
04/14/2023, 7:43 AMloading...
class FakeVC {
data class ViewState(val loading:Boolean = false, val content:String = "loading...")
private val screenState = MutableStateFlow(ViewState())
fun screenState() = screenState.asStateFlow()
fun somFakeCall(){
coroutineScope.launch {
screenState.value = screenState.value.copy(loading = true)
withContext(Dispatchers.Default){
delay(3000)
}
screenState.value = screenState.value.copy(loading = false, content = "I am here after api call")
}
}
//... some clear logic for scope on dispose
}
and the mutated state data change is never seen on the ui , and here is the compose code which is
val fvc = FakeVC()
MaterialTheme {
LaunchedEffect(Unit){
fvc.somFakeCall()
}
val viewState by l.screenState().collectAsState()
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center){
Text(viewState.content)
if(viewState.loading){
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center){
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center), color = Color.Red)
}
}
}
DisposableEffect(Unit){
onDispose {
fvc.clear()
}
}
}
this I tried it with latest coroutines and even with native-mt, is there anything else that may be required to setup it correctly when running it on iOS, as this works as expected on Android.Dima Avdeev
04/14/2023, 12:11 PMDima Avdeev
04/14/2023, 12:11 PMfun screenState() = screenState.asStateFlow()
humbledroid
04/14/2023, 12:12 PMDima Avdeev
04/14/2023, 12:12 PMhumbledroid
04/14/2023, 12:13 PMDima Avdeev
04/14/2023, 12:14 PMDima Avdeev
04/14/2023, 12:15 PMfun screenState(): StateFlow<ViewState> = screenState
humbledroid
04/14/2023, 12:27 PMDima Avdeev
04/15/2023, 9:06 AMval l = remember { FakeVC() }
humbledroid
04/15/2023, 9:50 AMDima Avdeev
04/15/2023, 3:52 PM