james
06/21/2022, 10:21 PMNavHost
, one Scaffold
and BottomNavigation
at the root level, with many nested screens & Composables under that: is there a recommended way to show and hide the BottomNavigation
?
I have a nested LazyColumn
which I’d like to use to trigger showing/hiding of that BottomNavigation
when I scroll up/down. this is fairly simple when the BottomNavigation
is “closer” to the Composable triggering it, but when it’s deeply nested I wonder what the best solution is?
do I simply pass a lambda like toggleBottomNavigationVisibility
all the way from the top level where the Scaffold
is, through many Composables, down into my deeply nested one? this would work but I would like to know if there’s a better way and my brain isn’t seeing it 😄Alex Vanyo
06/21/2022, 11:08 PMPostionIndicator
for Compose for Wear, but the same principle applies, since you’re trying to have a top-level component (in this case, a BottomNavigation
) be driven by state that is scoped to a specific destination (a LazyColumn
at some nested route)
The issue has the full details, but the summary is setting up a shared ViewModel
. You can use get access to that ViewModel
in two places: Outside the NavHost
to drive the BottomNavigation
visibility, and inside the NavHost
for the specific destination.james
06/22/2022, 2:16 AMColton Idle
06/22/2022, 10:34 AMjames
06/22/2022, 10:36 AMColton Idle
06/22/2022, 10:36 AMjames
06/22/2022, 10:41 AMAlex Vanyo
06/24/2022, 4:40 PMViewModel
route if the behavior is based purely on which route you are on. If you want it to be based on some state local to the destination (that you want saved properly), that’s where it gets trickier.