Now that androidx `ViewModel` can be used in KMP c...
# touchlab-tools
j
Now that androidx
ViewModel
can be used in KMP code I was just wondering if there is any way with SKIE to get functionality KMMViewModel provides to map
StateFlow
to properties in Swift?
s
How is that property used as opposed to using the AsyncSequence that Skie generates for you? Is it that KMMVM library does that plus also collects that sequence and stores it in a property automatically for you?
j
yeah, pretty much .....you can see examples of it in following https://github.com/joreilly/BikeShare/blob/main/ios/BikeShare/BikeShare/ContentView.swift
I guess some kind of helper could be added that does that
s
Ah I see, you get the VM and you can just do
vm.stateFlowVal
and you get it ready to use. I wonder if Skie has goals for such tight integrations with StateFlows. Also what if you do not want the StateFlow as a property but as a normal AsyncSequence for other callers? Is this an opt-in feature in that library too?
f
Hi! In theory SKIE can generate any Swift or Kotlin code based on the project code. So yes, there is a way. However, such functionality is technically out of scope for SKIE because SKIE focuses on the language itself and is currently architecture agnostic. On the other hand, this does not mean we will not consider it but it’s something we have to discuss internally first. It would certainly be an opt-in feature because not everyone would use it (similarly to what we have with the default arguments). Plus we will have to weigh the implementation complexity to the added benefits.
s
Also I think it’s be good to try and see how much code is it to do this yourself on a project and if it’s trivial the docs could just provide a snippet and leave it at that. At least for now
j
In the case of KMM-ViewModel it also uses it's own custom
MutableStateFlow
in shared code to allow this
this is what I've tried so far btw.....haven't looked yet at lifecycle aspects https://x.com/joreilly/status/1770735472114905257?s=20
Any more thoughts on this....seems like this would be a feature that would be used in most projects?
At this point with KMP-ObservableViewModel wrapping KMP version of Jetpack ViewModel, that's the primary scenario it addresses
f
@kpgalligan @Tadeas Kriz
t
Hey @John O'Reilly, I've been prototyping/experimenting with this for a while now and have 4 ways this can be handled in Swift/SwiftUI. Let's meet at KC, I'd love to show you what I've got so far and get your feedback
👍 1