adrielcafe / voyager

🛸 A pragmatic navigation library for Jetpack Compose
https://voyager.adriel.cafe
MIT License
2.31k stars 109 forks source link

Allow to create a navigator and pass it to Navigator #324

Open Kyant0 opened 3 months ago

Kyant0 commented 3 months ago

There are some cases where we want to use navigator outside of Navigator composable, now we can only get the navigator inside it and pass it to outside, which is not graceful.

The proposed API looks like:

val navigator = rememberNavigator(screens, key, disposeBehavior)
Navigator(navigator = navigator)
DevSrSouza commented 1 month ago

Can you provide use cases that how this would help? I mean, other libraries does this, but want to understand if there are real use cases that this can help or there are other ways to implement that same thing on voyager.

Kyant0 commented 1 month ago

For example, there is a view pager (navigation host) and bottom bar. We want to click bottom tabs to navigate to specific screen.

dae54 commented 1 month ago

I am looking for something similar, consider my usecase below. I am using compose for desktop.

BaseLayout( // Composable helper function that creates my base UI layout
    sidebar = { SideBar() },   // Sidebar composable
    body = {
         Navigator(LoginScreen())     // the body
         },
     footer = {}.   -- footer
 )

I am now facing a challenge since I need to be able to access to navigator inside Sidebar. If I try to access it now, it throws an error.

Is there anyone with a suggested approach?

I see if it could be possible to create navigator and be able to pass it down as props, would help in my usecase.