Issue with KMP and SwiftUI Screen Not Updating
ch8908 opened this issue · comments
Chien Shuo (Kros) Huang commented
Hi, I'm just trying out KMP and would like to know why this won't work on SwiftUI.
I tried to modify the sample code with an old-school ViewModel style:
private val _objects = MutableStateFlow(emptyList<MuseumObject>())
@NativeCoroutinesState
val objects: StateFlow<List<MuseumObject>> = _objects
fun fetchAll() {
viewModelScope.launch {
val data = museumRepository.museumApi.getData()
_objects.value = data
}
}
When calling fetchAll(), the code above works on Android, and the screen updates as expected. However, the screen doesn't update on SwiftUI.
I would really appreciate any guidance or suggestions you could provide. Thank you!