I’m trying to replace the `NavHost` by `AnimatedNa...
# compose
n
I’m trying to replace the
NavHost
by
AnimatedNavHost
, but I’m having an issue… Using
NavHost
I have this structure:
Copy code
@Composable
fun AppNavHost(...){
    val navController = rememberNavController()
    NavHost(navController = navController, ...) {
        composable("A") { ScreenA() }
        composable("B") { Feature1NavHost() }
    }
}
In
Feature1NavHost
I have another
NavHost
which takes control of the feature navigation. So,
ScreenA
calls “B” and pops out of the stack. Everything works fine here. Using
AnimatedNavHost
, when I press back in the first screen of
Feature1NavHost
, the display blinks and the application does not finish… 😕 I have to press a lot to close the app.
i
You'll want to upgrade to Navigation 2.4.0-alpha06 first (since Accompanist Navigation Compose depends on that version). That'll tell you if it is an issue with Navigation or Accompanist
c
Copy code
val navController = rememberAnimatedNavController()
n
I’m using
2.4.0-alpha06
and accompanist
0.16.1
@Chris Miller I know. the sample I shown is using
NavHost
😉
i
Also note that there are very few cases where you should actually use nested NavHosts, something we were just talking about earlier today: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1628603770177000?thread_ts=1628589309.155500&cid=CJLTWPH7S
What was saying is that you should verify that using 2.4.0-alpha06 without Accompanist works as you expect, then switch to Accompanist
As of course, Accompanist will inherit any issues of Navigation itself
👍 1
n
This combination is working:
Copy code
composeAccompanistVersion = '0.14.0'
composeActivityVersion = '1.3.0-rc01'
composeNavigationVersion = '2.4.0-alpha04'
composeVersion = '1.0.0-rc02'
I’ll update the libraries and let you know…
This combination
Copy code
composeAccompanistVersion = '0.16.1'
composeActivityVersion = '1.3.1'
composeNavigationVersion = '2.4.0-alpha06'
composeVersion = '1.0.1'
does not work 😕 it does not even open the nested graph
is there any workaround @Ian Lake?
i
Given that it works in our sample apps (nested nav hosts included), you're probably better off building a repro project and filing a bug. It is impossible to tell what is going on based on the code you've shared so far
I'd just really make sure you aren't calling
navigate
as part of composition - any animations will cause you to recompose multiple times (and you really don't want to navigate every frame of your animation)
n
think smart I guess I found a possible issue (on my end) related to that… let me see
I was calling
navigate
in the composition… 🤦‍♂️ thanks @Ian Lake
i
Ah, glad you were able to track it down. You're not the only one that ran into that
👍 1
n
Was it working before because has no animation in the previous version?
i
Correct, in alpha04 and earlier, it was all instant jump cuts so your destination would ~never recompose
👍 2