Hi there, I hope you all are doing well. I am an A...
# compose-ios
k
Hi there, I hope you all are doing well. I am an Android developer and I am starting to figure out about KMM. I would like to know if it is a way to do the navigation UI for both platforms IOS and Android. Because I have been looking for it but I have not found a way to do it to not code in Swift. i just want to make the UI with Kotlin.
👍 1
k
are those libraries allow you to do the IU just with kotlin ? and don't use swift
a
Yes, they are
k
Ah ok i will try it. Thank you so much !!
The dependencies and logic should be in the commonMain shared module right ?
to setup the navigation from both platforms
a
I think yes, if all platforms that you are targeting are supported by Compose.
k
Yes i just want to test it for Android and IOS
j
What I did was using androidx navigation compose library only for Android with expect / actual. And for iOS very similar but not using Android lifecycle stuff, just a simple AnimatedContent with when block handling each navigation route. Created my own navigation controller to delegate current route between Android and iOS wrapping Googles navcontroller (only in actual androidMain) We will have transitions in soon releases. Would ofc be possible using Decompose but having imo larger impact on structure of codebase. With this solution I can also easy switch between native variants or compose MP variant if needed without refactor everything.
Would be fairly easy adopt for back callback, nested navigation stacks and dialog if needed. Some semi possible in Decompose. But as I know in Android 14 and upcoming androidx navigation changes I prefer Googles maintenance level.
k
• Why when i have had added a new kotlin file even if i am not using it yet in my App.kt in the commonMain i get this error when i try to build in IOS failed with code: 65
a
Sure, if this works for you!
Also please note that you will also likely need to preserve the UI state manually on iOS. E.g. when you scroll a list, then go to details, then back - the scroll position will be probably reset.
k
I have had added voyager when i run it in Android works but it is not working in IOS it fails
Copy code
sourceSets {
    val commonMain by getting {
        dependencies {
            implementation(compose.runtime)
            implementation(compose.foundation)
            implementation(compose.material3)
            implementation(compose.material)
            @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
            implementation(compose.components.resources)
            val voyagerVersion = "1.0.0-rc05"

            // Navigator
            implementation("cafe.adriel.voyager:voyager-navigator:$voyagerVersion")
            // BottomSheetNavigator
            implementation("cafe.adriel.voyager:voyager-bottom-sheet-navigator:$voyagerVersion")
            // TabNavigator
            implementation("cafe.adriel.voyager:voyager-tab-navigator:$voyagerVersion")
            // Transitions
            implementation("cafe.adriel.voyager:voyager-transitions:$voyagerVersion")
            // Android ViewModel integration
            implementation("cafe.adriel.voyager:voyager-androidx:$voyagerVersion")
        }
    }
    val androidMain by getting {
        dependencies {
            api("androidx.activity:activity-compose:1.6.1")
            api("androidx.appcompat:appcompat:1.6.1")
            api("androidx.core:core-ktx:1.9.0")
            api("androidx.navigation:navigation-compose:2.5.3")
        }
    }
    val iosX64Main by getting
    val iosArm64Main by getting
    val iosSimulatorArm64Main by getting
    val iosMain by creating {
        dependsOn(commonMain)
        iosX64Main.dependsOn(this)
        iosArm64Main.dependsOn(this)
        iosSimulatorArm64Main.dependsOn(this)
    }
a
And Decompose also supports predictive back gestures on all platforms, in case you ever need this.
k
I tried voyager but the build fails in. IOS it just build in android. I don't know if I should add something else
This could happen if there are two libraries, where one library was compiled against the different version of the other library than the one currently used in the project. Please check that the project configuration is correct and has consistent versions of dependencies. Cannot infer a bundle ID from packages of source files and exported dependencies, use the bundle name instead: shared. Please specify the bundle ID explicitly using the -Xbinary=bundleId=<id> compiler flag. There are still 3 unbound symbols after generation of IR module <shared>: Unbound public symbol IrSimpleFunctionPublicSymbolImpl: cafe.adriel.voyager.navigator.tab/Tab.icon.<get-icon>|-5764684600227404327[0] Unbound public symbol IrSimpleFunctionPublicSymbolImpl: cafe.adriel.voyager.navigator.tab/Tab.options.<get-options>|7766868889533212780[0] Unbound public symbol IrSimpleFunctionPublicSymbolImpl: cafe.adriel.voyager.navigator.tab/Tab.title.<get-title>|371973571756195065[0]
i solved it!! Thanks guys!!
a
Btw, I completely forgot about this beautiful library https://github.com/xxfast/Decompose-Router, if you want features from Decompose but at the same time prefer simple Composable API for stack navigation.
k
Thank you so much!! I really appreciated it 🙌
m
The unbound symbols bug is a Compose Ios issue that the Compose compiler needs to fix, just don't use the tab-navigator dependency for now and you wont get the issue.
k
hey guys i would like to know if it is a way to add Google Map in KMM. I mean just using kotlin i should use swift too to be able to display it in IOS ?