raamcosta / compose-destinations

Annotation processing library for type-safe Jetpack Compose navigation with no boilerplate.
https://composedestinations.rafaelcosta.xyz
Apache License 2.0
3.21k stars 132 forks source link

Destinations with BottomSheet style in backstack #249

Closed Sabriel1984 closed 2 years ago

Sabriel1984 commented 2 years ago

Hi, thanks for your library, I think it's great but I encounter to major problems which blocks me in my project:

  1. I show some views as modal (so with BottomSheet adnotation in Destination) - i.e. details view - and the problem is a) that when I navigate to another view and go back my BottomSheet view is not available in backstack navigation (so it is hidden) and I have gap in navigation b) it's impossible to show second BottomSheet view from first one without hide first one... so basically BottomSheet view is treated as Dialog and a) not present in back navigation b) only one could be shown is it possible to force somehow not hide those modal views?

  2. DestinationNavigator is available only as parameter in @Composable with Destination adnotation - so if I have parts of view in different Composable functions I need to pass navigator as parameter to all of them. Is it possible to get naviagtor instance in different way or save it somewhere to made it available to whole app?

raamcosta commented 2 years ago

Hi @Sabriel1984 👋

1) This is expected. It is how it works with official Compose Navigation as well as any other jetpack navigation library. Read more here: https://stackoverflow.com/questions/67237079/how-to-prevent-bottomsheetdialogfragment-from-dismissing-after-a-navigation-to-a (first answer by Ian Lake)

2) What exactly is wrong with passing it down? The official recommendation is to pass lambdas for all your Composables to navigate, so you can do the same here: receive DestinationsNavigator in the Composable which is annotated with @Destination and then use that in lambdas you pass down to all other Composables that need them. (like { navigator.navigate(SomeDestination) }) Alternatively, if you really don't want to follow this recommendation, you could use CompositionLocal feature (google it, should be easy to find) to make it an implicit dependency, but this is really not recommended. Also, you cannot make it globally available because that would leak it when activity is recreated. Keep in mind also that if you want to do navigation in the same place you're calling DestinationsNavHost, then you can just use the NavController and pass it to DestinationsNavHost.