Hi, can anybody give advice on whats the best way ...
# compose-ios
f
Hi, can anybody give advice on whats the best way to couple a viewmodel with compose-ios? is it expect actual? or is KMM viewmodel a better solution, which is from what i Have understood an implementation of expect actual packed in a library. Or is better to wait for circuits to release iOS support?
👍 1
v
It is absolutely common for the KMP libraries to be just the expect/actual wrappers for native stuff we already have in android and iOS. So you are free to use one of the libraries. If they provide something good for you. Or you can simply make your own expect/actual implementation and check in the libraries how they work around common issues
p
I think both Voyager and Decompose provides Viewmodel which can be used common. But i am not sure if it survives config change in Android , Well just lock it to portrait
d
Does anyone have a sample project targeting this or is there someone that would like to work on this together maybe?
p
You can use ViewModels with decompose, and it survivives configuration changes and process death in the supported platforms. In Voyager the ViewModel is scoped to the composable lifecycle, is not scope in an Android ViewModelStoreOwner, at least the last time I checked the code. You have to be aware the composable lifecycle is not the same as the regular Activity/UiViewController lifecycle. Other than that you can use any of those. There are 2 major aspects of the Android ViewModel, survive config changes and/or process death. Both are popular in Android but not so much in other platforms so you can have your own ViewModel implementation that is just a regular State/StateController class that lives in the scope of your Composables tree,(similar to Voyager), just remember it. You can have a CompositionLocalProvider that provides the ViewModels Factory to any Composable that needs it, for DI purposes
a
There is also another important use case of a ViewModel with Compose - it is supposed to live as long as the related screen is in the back stack. E.g. this is how it works in navigation-compose and Decompose.
p
That too, although that holds true for any state controller instance scoped to that screen right?
f
Ah thanks for the advice that’s nice. I am studying the content on https://arkivanov.github.io/Decompose/ and watching the

https://www.youtube.com/watch?v=DBxiOKRKQ34

about the decompose lib in Russian with auto generated english subs. I hope the translation is clear enough to understand what is being said 😄
a
That too, although that holds true for any state controller instance scoped to that screen right?
I think that's the responsibility of the navigation library. Compose itself doesn't have this. So if you are DIY, then most likely you will have to handle it on your own.
p
I got your point
f
@Arkadii Ivanov Ah super thanks. 👍
Hello, If I add this dependency implementation(“com.arkivanov.decomposeextensions compose jetbrains1.0.0-alpha-05”) to commonMain I get the following errors •
Could not resolve com.arkivanov.decompose:extensions-compose-jetbrains:1.0.0-alpha-05 for :shared:iosArm64Main
Could not resolve com.arkivanov.decompose:extensions-compose-jetbrains:1.0.0-alpha-05 for :shared:iosArm64Test
Could not resolve com.arkivanov.decompose:extensions-compose-jetbrains:1.0.0-alpha-05 for :shared:iosSimulatorArm64Main
Could not resolve com.arkivanov.decompose:extensions-compose-jetbrains:1.0.0-alpha-05 for :shared:iosSimulatorArm64Test
Could not resolve com.arkivanov.decompose:extensions-compose-jetbrains:1.0.0-alpha-05 for :shared:iosX64Main
Could not resolve com.arkivanov.decompose:extensions-compose-jetbrains:1.0.0-alpha-05 for :shared:iosX64Test
Failed to resolve: org.jetbrains.compose.foundation:foundation:1.2.0-beta02
Any here who can help me solve this issue
a
Ah, more and more people are pumping into this. Currently, Compose for iOS support is published from a separate branch, so you have to use a special version for all your Decompose dependencies. See this doc: https://arkivanov.github.io/Decompose/extensions/compose/#compose-for-ios-macos-and-web-canvas Also 1.0.0-alpha-05 is pretty old. You can try using
1.0.0
, or the latest
2.0.0-beta-01
. But from the experimental branch.
f
@Arkadii Ivanov I havent added compose-ios to the project yet. I first wanted to add decompose and add components. Do I have to add the extensions-compose-jetbrains depency in iosMain part as an api?
a
The error says that it compiles
extensions-compose-jetbrains:1.0.0-alpha-05
for iOS. This module's version doesn't support iOS.
I first wanted to add decompose and add components.
In this case, you can try removing
extensions-compose-jetbrains
from your module where you are adding components. At least for now.
But if you are planning to add Compose for iOS in the future, you will need to use
compose-experimental
version anyway.
f
Check. I have updated it to 2.0.0-beta-01 and ik will try to find out what the issue is. Thnx for your help 👌
a
Just FYI,
extensions-compose-jetbrains:2.0.0-beta-01
still won't compile for iOS, you will need to use
extensions-compose-jetbrains:2.0.0-compose-experimental-beta-01
.
f
I understand. Thank you very much