Not really. The ViewModel is already different based on the platform. You can check BaseViewModel wherein on Android, it uses Architecture Components, and on iOS, it's just a custom implementation.
I beg to differ, the ViewModel can be shared. Ideally, it shouldn't have a dependency on the platform's framework. You have the view (aka Fragment / Activity / ViewController) for that. For example:
There's no platform-specific implementation. It's just pure logic.
The watch function on the CFlow class is just sort of an extension for iOS which you can choose to use or not in Android. iOS cannot get suspend functions which is why we have to resort to some workaround for now.
You can choose to use the expect/actual implementation for CommonFlow and use the normal Flow in Android and use CFlow for iOS however this makes you unable to test it in commonTest since this sourceSet will use commonMain and in the declaration, it's not a Flow and you can't let and expect declaration inherit from something so you have to create both of the tests in androidTest and iosTest
I think exposing a function doesn't hurt. It's not like we changed the whole implementation. We just added something for it to be used on the other side.
But that's my opinion and what's worked for me so you can still go ahead and try your implementation out and see if it works for you. :)
TL;DR Add a watch function so we can use Flow on iOS vs. Write them separately on each platform. I go for using watch
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Not really. The
ViewModel
is already different based on the platform. You can checkBaseViewModel
wherein on Android, it uses Architecture Components, and on iOS, it's just a custom implementation.I beg to differ, the ViewModel can be shared. Ideally, it shouldn't have a dependency on the platform's framework. You have the view (aka
Fragment
/Activity
/ViewController
) for that. For example:There's no platform-specific implementation. It's just pure logic.
The
watch
function on theCFlow
class is just sort of an extension for iOS which you can choose to use or not in Android. iOS cannot getsuspend
functions which is why we have to resort to some workaround for now.You can choose to use the
expect/actual
implementation forCommonFlow
and use the normalFlow
in Android and useCFlow
for iOS however this makes you unable to test it incommonTest
since this sourceSet will usecommonMain
and in the declaration, it's not aFlow
and you can't let andexpect
declaration inherit from something so you have to create both of the tests inandroidTest
andiosTest
I think exposing a function doesn't hurt. It's not like we changed the whole implementation. We just added something for it to be used on the other side.
But that's my opinion and what's worked for me so you can still go ahead and try your implementation out and see if it works for you. :)
TL;DR Add a
watch
function so we can useFlow
on iOS vs. Write them separately on each platform. I go for usingwatch