Hi all, I was trying out Compose ios (alpha) and g...
# compose-ios
m
Hi all, I was trying out Compose ios (alpha) and got stuck at one point. I needed to consult you for your opinion. I am attaching a screenshot that shows a small part of both iOSApp and Android App project. Attached you can see viewModels , Activity/ContentView. Just like Android, I am trying to update the content on iOS, but it’s not working by using binding<state> etc. How can I get the redraw action on iOS? Any ideas or examples would be very helpful :) Have a nice K / K cheers
1
👀 1
m
d
you can create a state and store it in
val stateFlow = MutableStateFlow<YourState>(...)
After that - you can subscribe to state changes with in Composable function with:
val state = stateFlow.collectAsState()
And draw that state:
Text(state.value.toString())
state.value will have a type of YourState
t
It appears you are using KMPNativeCoroutines. Then on the Kotlin side, put @NativeCoroutinesState above your val state. Then on the iOS side wrap the generated stateFlow with the KMPNativecoroutines.createObservable method, then use the RxSwift observe methods...
m
Thanks all, The requirement is , updating the ComposeUIView by using ViewModel.swift: ObservableObject. Fetching data is OK but updating it. I’m able to draw a composeView with default state , and it never gets updated 🙂 I need a trick which refreshes my rootComposable
d
Also, you can simply use in Kotlin Composable functions:
val state = remember{ mutableStateOf(MyState()) }
Read and change this state
state.value