hey <@U0234N0QYSK> I've got a question with how I ...
# compose-destinations
r
hey @Rafael Costa I've got a question with how I might use specific animation for bottom bar navigations vs. pushing to an item. I currently have a single navigation graph with all of my destinations with the bottom bar similar to your example:
Copy code
BottomBarItem.entries.forEach { destination ->
          val isCurrentDestOnBackStack by
            navController.isRouteOnBackStackAsState(destination.direction)
          NavigationBarItem(
            selected = isCurrentDestOnBackStack,
            onClick = {
              if (isCurrentDestOnBackStack) {
                // When we click again on a bottom bar item and it was already selected
                // we want to pop the back stack until the initial destination of this bottom bar
                // item
                navigator.popBackStack(destination.direction, false)
                return@NavigationBarItem
              }

              navigator.navigate(destination.direction) {
                // Pop up to the root of the graph to
                // avoid building up a large stack of destinations
                // on the back stack as users select items
                popUpTo(NavGraphs.root) { saveState = true }

                // Avoid multiple copies of the same destination when
                // reselecting the same item
                launchSingleTop = true
                // Restore state when reselecting a previously selected item
                restoreState = true
              }
            },
            // ...
          )
        }
      }
Is there a way within a subclassed
DestinationStyle.Animated()
to see whether navigation is occurring from this bottom bar or is there a way through nested navigation graphs to achieve this (seems heavy handed for animation)?
d
Wouldn't the target of the destination help?
Copy code
when (initialState.destination()) {
                LoginDestination -> fadeIn()
                else -> EnterTransition.None
            }
r
if tab A is Home -> Search and tab B is Profile -> Settings, the animation would have initial state as settings and target state as search, both of which should have push/pop animation typically, but navigating by tapping the tab bar should not
r
Hi! The only way I can think of is to use a navigation argument “shouldAnimate : Boolean = true” and when navigating from tabs set it to false. Then in the animation spec you can get the arguments from the NavBackStackEntry (entry.navArgs<MyArgs>().shouldAnimate) and check it.
r
interesting approach! I'll give it a try. Thanks @Rafael Costa
if my Home destination has
shouldAnimate
is false, but that nav stack has additional destinations on it from its saved state, even if from my bottom bar I'm navigating to the Home destination, the target destination is its deepest destination on the stack. Is there a way to read the destinations root item on its stack?