Ahmed Mourad
09/19/2023, 1:43 AMAhmed Mourad
09/19/2023, 1:44 AMclass MyViewModel {
val state: MutableStateFlow<...> = ...
val action: MutableSharedFlow<...> = ...
}
and my shared ui would look like this:
@Composable
fun MyUI(
state: StateData,
onStateChange: (StateData) -> Unit,
performAction: (ActionData) -> Unit,
modifier: Modifier = Modifier
)
to use that with SwiftUI I wrap MyUI
in a ComposeUIViewController
which's wrapped inside a UIViewControllerRepresentable
which enables me to use it as a SwiftUI view, so I have a few questions:
1. where's the best place to create my viewmodel? is it directly inside the swiftui view as follows?
struct MySwiftView: View {
let model = MyViewModel(...)
var body: some View {
MyComposeView()
}
}
2. how do I collect the state flow to use with swiftui, I don't expect it to react to changes in flow.value
out of the box? does it?
3. where do I collect my action flow? on Android I would just collect the action flow in a LaunchedEffect with a Unit key. My current candidate is onAppear
but i'm not sure about it. my action flows mostly contain navigation actions like navigating up and navigating to the next screen which i'll be using with navigation links with tags and selections.
Thank you!Jeff Lockhart
09/19/2023, 5:05 AMTadeas Kriz
09/19/2023, 9:56 AM