https://kotlinlang.org logo
#compose
Title
# compose
c

Can Korkmaz

04/04/2022, 7:45 AM
Hello, I've some questions regarding compose bottom navigation and navcontroller. I have my navController defined in navigation composable which has routes screen, and bottom navigation bar has 4 Screens. I need current navBackStackEntry and current destination in NavigationBar composable, so to get access to them should I pass navController to HomeScreenComposable and there down to BottomNavigaitonBar? I though it was bad practice to pass navController to composables for testing purposes. Also can i just re-instantiate a navController inside BottomNavigation, would I receive the same navController with the one in main Navigation composable(just above NavHost), I think not? I have enum class and list of tabs declared already by the way. correction: navController defined inside mainActivity inside setContent
c

czuckie

04/04/2022, 7:48 AM
I think a more optimal approach would be for the bottom nav bar to be able to communicate upwards a desire to change the current screen
c

Can Korkmaz

04/04/2022, 7:52 AM
So are you saying that I should pass the navController to HomeScreenComposable (hosts Scaffold with bottomNavigation) and then pass down to bottomNavigation? I was told to never pass navController and instead pass lambdas, but it looks like I have no other options.
c

czuckie

04/04/2022, 8:17 AM
No, I'm saying you should pass a lambda down which will be created at the top level, and passed down to the bottom navigation, such that on a tab being selected, you'd invoke the lambda with an enum value or equivalent such that at the top where your nav controller is you can handle the navigation
c

Can Korkmaz

04/04/2022, 8:20 AM
Yes I understand now, just like the normal navigation inside composables. Thank your for your help
2 Views