Bradleycorn
12/18/2023, 6:07 PMScaffold
. It’s content slot contains a NavHost
that displays a “screen” composable for the current destination. It’s similar to the Now In Android sample app from Google.
I’m curious how to best manage a FloatingActionButton (FAB) with this kind of architecture? the FAB’s display state is based on the current NavGraph destination that is being displayed by the NavHost. Some screens need to show a FAB, and others don’t. Managing the display state is pretty simple to do, setting the state based on the current destination.
Handling FAB click actions seems less straight forward. The action to take could vary significantly based on which destination/screen is displayed when the FAB is clicked. In some cases, it may be a simple navigation action. In others it may be more complicated (say, show a modal bottom sheet with content based on a selected item). I’m struggling with a good way to architect this. My brain keeps wanting to pass the FAB click action down to the currently displayed screen composable to let it handle it. But of course that breaks the primary rules of Unidirectional Data Flow.
How do you all handle cases like this?Stylianos Gakis
12/19/2023, 12:36 AMbrandonmcansh
12/19/2023, 2:50 AMBradleycorn
12/19/2023, 2:19 PMStylianos Gakis
12/19/2023, 2:26 PMBradleycorn
12/19/2023, 2:27 PM