voyager icon indicating copy to clipboard operation
voyager copied to clipboard

Navigation to Screen from bottom sheet

Open Kashif-E opened this issue 1 year ago • 12 comments

How can we navigate to a screen from a bottom sheet? if I do bottomSheetNavigator.show(ScreenA()) and then navigator.push(ScreenB()) it will be another bottom sheet. How can i do the opposite?

Kashif-E avatar Dec 21 '23 10:12 Kashif-E

Hey, sorry the delay!

Don't know if I understand your question properly, do you want to navigate to another Screen inside the BottomSheet or you want to navigate to Screen of the a Navigator that is the Content of the Scaffold? Can you give me some examples?

DevSrSouza avatar Dec 26 '23 11:12 DevSrSouza

Hey! Sorry for the delay, consider this glow when moving from a bottom sheet to a non-bottom sheet screen. ezgif-2-b460334530

Kashif-E avatar Jan 15 '24 15:01 Kashif-E

@Kashif-E same problem, have you found any solution?

akhbulatov avatar Apr 12 '24 15:04 akhbulatov

@DevSrSouza is there a recommended solution for such a case?

akhbulatov avatar Apr 12 '24 15:04 akhbulatov

Same here. Does anyone have some solutions?

mrcsxsiq avatar Jun 24 '24 19:06 mrcsxsiq

👋 We're also looking for a solution to this. The structure we adopt is the root composable of our application hosts the BottomSheetNavigator. For example:

@Composable
fun App() {
    BottomSheetNavigator {
        Navigator(screen = MainScreen())
    }
}

When in a bottom sheet screen, LocalNavigator.currentOrThrow is thus the BottomSheetNavigator, which explains why all screens launched from this context open as bottom sheets. LocalNavigator.currentOrThrow.parent is, of course, null.

I think BottomSheetNavigator needs a variant where BottomSheetNavigatorContent is a Navigator, where such Navigator is made available via a CompositionLocal?

sausti avatar Jul 26 '24 14:07 sausti

you can pass a navigator to the bottom sheet and then use that inside the bottom sheet to open a new screen instead of the bottom sheet

Kashif-E avatar Jul 26 '24 15:07 Kashif-E

you can pass a navigator to the bottom sheet and then use that inside the bottom sheet to open a new screen instead of the bottom sheet

This solution worked for me. Thank you @Kashif-E

mrcsxsiq avatar Aug 03 '24 04:08 mrcsxsiq

you can pass a navigator to the bottom sheet and then use that inside the bottom sheet to open a new screen instead of the bottom sheet

if you put the app in the background while bottom sheet is open, app will crash because of Parcelable IOException. I can repeat the crash continuously.

akardas16 avatar Aug 06 '24 07:08 akardas16

@akardas16 yes you are right, the navigator is not parcelable/serializable. Another option is to pass a result to the original bottom sheet caller; upon receiving the result, you can navigate to the next screen. you can use one of the ways mentioned in this repo for result passing.

navigate to the bottom sheet from screen A-> hide the bottom sheet with the result -> get the result in screen A and navigate to screen B

Kashif-E avatar Aug 06 '24 10:08 Kashif-E

@akardas16 yes you are right, the navigator is not parcelable/serializable. Another option is to pass a result to the original bottom sheet caller; upon receiving the result, you can navigate to the next screen. you can use one of the ways mentioned in this repo for result passing.

navigate to the bottom sheet from screen A-> hide the bottom sheet with the result -> get the result in screen A and navigate to screen B

I have tried a few options which mentioned but looks like they are not working as expected. there is no reason to not using ModalBottomSheet if needs result from bottom sheet. it works like a charm

akardas16 avatar Aug 06 '24 16:08 akardas16

Can you explain?

Kashif-E avatar Aug 08 '24 06:08 Kashif-E