https://kotlinlang.org logo
Title
n

nglauber

08/10/2021, 6:37 PM
I’m trying to replace the
NavHost
by
AnimatedNavHost
, but I’m having an issue… Using
NavHost
I have this structure:
@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

Ian Lake

08/10/2021, 6:50 PM
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

Chris Miller

08/10/2021, 6:51 PM
val navController = rememberAnimatedNavController()
n

nglauber

08/10/2021, 6:51 PM
I’m using
2.4.0-alpha06
and accompanist
0.16.1
@Chris Miller I know. the sample I shown is using
NavHost
😉
i

Ian Lake

08/10/2021, 6:53 PM
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

nglauber

08/10/2021, 7:09 PM
This combination is working:
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
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

Ian Lake

08/10/2021, 7:25 PM
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

nglauber

08/10/2021, 7:29 PM
: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

Ian Lake

08/10/2021, 7:37 PM
Ah, glad you were able to track it down. You're not the only one that ran into that
👍 1
n

nglauber

08/10/2021, 7:38 PM
Was it working before because has no animation in the previous version?
i

Ian Lake

08/10/2021, 7:49 PM
Correct, in alpha04 and earlier, it was all instant jump cuts so your destination would ~never recompose
👍 2