Compose v1.0.3 supports Kotlin 1.5.30:tada:
# compose
o
Compose v1.0.3 supports Kotlin 1.5.30šŸŽ‰
šŸŽ‰ 16
n
a
I'm happy we can use the latest. Is there anything that will make compose dev experience better with this release? I've looked at the release notes. I can't find much.
n
I’m particularly waiting for this fix… It’s causing problems in my current project… https://issuetracker.google.com/issues/195668143
i
https://github.com/google/accompanist/pull/722 was merged 3 days ago, so any snapshot builds should already be compatible if you want to give those a try
n
I’m using the following lib versions:
Copy code
appCompatVersion = '1.4.0-beta01'
composeAccompanistVersion = '0.18.1-SNAPSHOT'
composeNavigationVersion = '2.4.0-alpha10'
composeVersion = '1.0.3'
navVersion = '2.4.0-alpha10'
But I’m getting this error šŸ˜•
Copy code
java.lang.NoSuchMethodError: No static method rememberNavController(Landroidx/compose/runtime/Composer;I)Landroidx/navigation/NavHostController; in class Landroidx/navigation/compose/NavHostControllerKt; or its super classes (declaration of 'androidx.navigation.compose.NavHostControllerKt' appears in /data/app/com.investcorp.mobile-b0FahXhLXqmtLHdJOugYqQ==/base.apk)
        at com.google.accompanist.navigation.animation.NavHostControllerKt.rememberAnimatedNavController(NavHostController.kt:36)
i
Ah, sounds like you might need https://github.com/google/accompanist/pull/747 to be merged in also (alpha10 changed binary compatibility). That should be merged tomorrow
n
ok… thanks @Ian Lake šŸ™ 😊
i
And Accompanist 0.19.0 is out now šŸ˜„
ā¤ļø 1
n
@Ian Lake do you guys finally denied to pass
Parcelable
/
Serializable
as parameters in the navigation? (I know you guys are very opinionated about that)
i
Did you already see the custom NavType support added back in alpha08? https://issuetracker.google.com/issues/196871885#comment6
n
No, I didn’t… šŸ˜ž I’ll try to use it…
Ok. It worked šŸŽ‰ partially 😩 A total unrelated issue… I have something like this:
Copy code
*AppNavHost* { 
    AnimatedNavHost {
        composable("onboarding") {
            *OnboardingNavHost* {
                AnimatedNavHost { my onboarding screens here }
            }
        }
        composable("feature1") {
            *Feature1NavHost* {
                AnimatedNavHost { my feature1 screens here }
            }
        }
    }
}
What’s happening is: I’m displaying a screen declared in
Feature1NavHost
, from there I’m calling a callback declared in
AppNavHost
which do the following:
Copy code
val navOptions = NavOptions.Builder()
    .setPopUpTo("feature1", true)
    .build()
navController.navigate(
    "onboarding",
    navOptions
)
The idea here is navigate from Feature1 to Onboarding. However, one of the composables declared in
OnboardingNavHost
has a deep link declared in it which is always called šŸ˜• event I set a totally different start route…
Copy code
composable(
    "activateAccount",
    arguments = ...,
    // Removing this line, everything works...
    // deepLinks = OnBoardingRoutes.AccountActivation.getDeepLinks() 
) { ... }
Any thoughts? šŸ˜•
i
I'm sorry, you're so far off the recommended path, that I really can't help.
n
Well… 1. it was working on previous version šŸ˜• 2. also, why can we have nested graphs in regular navigation and not in compose? (https://developer.android.com/guide/navigation/navigation-nested-graphs) I’m using the same principle here… šŸ˜• Anyways.. can you provide at least some direction for multi module projects and navigation? Because the entire navigation in a single file/function seems not good to me…
i
No, you're doing something entirely, completely different than nested graphs - you're doing nested NavHosts. Nested graphs are absolutely supported in Navigation Compose (https://developer.android.com/jetpack/compose/navigation#nested-nav) and that's exactly the building block you should be using to support each module providing its own graph (https://developer.android.com/guide/navigation/navigation-multi-module). This is something we've talked about previously: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1631295818240300?thread_ts=1631295578.239400&cid=CJLTWPH7S
n
Thanks for the references. I’ll try to follow them. šŸ‘ I’ll post the results here…
Ok… Just leaving some notes here for future references… The issue that I mentioned above was happening because my composable/route had both
arguments
and
deepLinks
. I just need the deep links, so when I removed the arguments, it worked. The custom
NavType
also worked fine. Everything is working now using nested
NavHosts
. šŸ™ @Ian Lake, I’m genuinely curious about your recommendation against using nested
NavHost
. You know more than everyone, after all, you’re part of the team that build it. So I really want to hear from you… I tried migrate to nested navigation, but I faced a few problems in comparison with my current approach: 1. How can pass a parameter to a nested graph? For instance: I have a
ScreenA
in the
Module1
, this screen load some status and redirect to
Module2
. But the logic for which screen in
Module2
should be displayed should be executed in
Module2
. How can I do that? Should I have ā€œfakeā€ route to do this logic and then redirect properly? 2. Based on the problem above (a dynamic start route), how can create a
hiltViewModel
scoped to a
navigation
? Currently, I’m using the
NavBackStackEntry
from the root of my module. How could I do the same? 3. If I use a
navigation
to represent the tabs of a BottomNavigation, when I select a given tab, should I replace the entire content? So every tab would have a bottom navigation bar? In my current implementation, a
NavHost
is the content of my
Scaffold
, so as soon I navigate using the
navController
, the content is shown properly. I truly appreciate your help. Thanks in advance.