Open thomaskioko opened 6 months ago
I imagine its possible, the main thing with ScreenModels is that they are stored in the ScreenModelStore, if you implement the Screen interface or create a screen with a unique key, I imagine you could add it to the ScreenModelStore manually and manage its lifecycle with whatever iOS lifecycle APIs there are.
Thanks @Syer10. I was hoping it was something supported out of the box. It was pretty easy wiring things up on the Android side (thanks to Tachidesk 😉 ). Anyway, I'll give it a shot and see what happens. Thanks again.
hey @thomaskioko . I was also looking for the same thing myself. Did you make it work? I couldn't even add voyager dependency (which includes ScreenModel) to commonMain because it's dependent to jetpack compose.
Hey @osrl I'm glad to know I'm not the only one who would like this. I just set it up on Android. I am yet to try to hack something out with the suggestion. Hopefully over the weekend.
I'm not sure if that's currently possible. Please let me know if you achieve something
I'm also in the same situation. Looking forward some solution.
We have here (where I work) a custom ScreenModel/ViewModel that the Lifecycle is bound on Voyager lifecycle and on iOS, the UiViewController lifecycle.
But this is a complete custom implementation that the porpuse is to only call onDispose
and free a CoroutineScope based on the platforms lifecycles. I don't see how things can be a fit to Voyager ScreenModel that was designed to work with Compose and the Navigator/Screen lifecycles.
The ScreenModel/ViewModel interface is pretty simple, you can build a custom easily and where you use Voyager, bound to the lifecycle of the Screen by using ScreenLifecycleStore
APIs.
https://voyager.adriel.cafe/lifecycle#extending-the-lifecycle-lazily
@thomaskioko @osrl @jeancsanchez Are you got success to integrate it on iOS side ?
@swapnil-musale, I didn't have much time to try to hack something with the suggestions from folks in the comments. I ended up going with a different library. (decompose)
Is it possible to access a ScreenModel in SwiftUI or does my app need to be a compose-multiplaform? I want to keep the UI side native per platform (Android: Compose & iOS SwiftUI) and only share the "ViewModel".