-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiplatform support #91
Comments
Hi Emil, thanks for the detailed description! I'm also a user of the KMP-ObservableViewModel lib (when it was called KMMViewModel 😅) in my pet project and indeed the As for your second solution, that's exactly how KMP-ObservableViewModel is solving the problem in SwiftUI, although the order is slightly different, in there they register the diInit when the observable is created and the VM Store is created only at the last minute (just to call the protected clear method). Now for your request, I'm thinking about it but I'm still in the early exploration phase, especially since Google introduced KMP support for Android VIewModels). Next step after testing resaca with the new KMP ViewModel: decide if resaca will support SwiftUI and I'll update this issue with the outcome. |
I've just found this other implementation following the same options discussed in this thread, the more alternatives the better for reference Original reference from this tweet https://x.com/joreilly/status/1795528038781710465 |
I am really interested in KMM support. I am using the latest androidx.lifecycle viewmodel, and sadly, I can not use this library because I am using compose multiplatform and I share the UI between both iOS and android versions. Is there any plan to add support for it in a near future? Thanks in advance |
@enoler Yes, the support for Compose Multiplatform is actually in progress, I made some initial feasibility designs and it looks quite simpel for iOS so I´ll start the implementation this week. By the way, Compose multiplatform is quite different from the SwiftUI support discussed above in this ticket. Since resaca is a library for Compose, the integration without Compose in a SwiftUI project is simpler and different than all the work that resaca does, so it doesn't really fit in this library. I'm still deciding if it's better to leave SwiftUI as a documentation guide or for another project/library. |
Happy to read that, in my case I am not using viewmodels on the swift UI, I am handling everything inside compose, so I just import the main composable on swift and the rest it's doing the magic under the hood inside compose. |
Work for Compose Multiplatform support is tracked on this feature branch #123 |
Compose multiplatform support has been released 🎉 See 4.0.1 (and 4.0.0) https://github.com/sebaslogen/resaca/releases |
Hi! Now that the Jetpack lifecycle and view model libraries have multiplatform support, I was wondering if this library could be made multiplatform compatible. In my case, I'm thinking of iOS, and being able to scope a
ViewModel
to a SwiftUIView
.I know of two solutions so far:
KMP-ObservableViewModel solution where using the
@StateViewModel
annotation will take care of the lifecycle and ensure the view model is cleared when theView
is destroyedThis solution, that I'm currently using myself, and seems to work fine, though there's a bit of boilerplate involved (maybe because I don't know any better):
In the iOS app, create a
ViewModelOwner
class that implements theViewModelOwner
interface. This requires the shared module to export the Jetpack viewmodel library.Then in a
View
implementation:I'm using the second method because I don't need all the other stuff
KMP-ObservableViewModel
offers - I prefer to use SKIE to handleFlow
s.But I started wondering if it wouldn't be possible to make
viewModelScoped()
work inside a SwiftUIView
.Best regards,
/Emil
The text was updated successfully, but these errors were encountered: