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

Bradleycorn

11/10/2020, 2:01 PM
I’m excited for the new
navigation-compose
library. But, the examples in the documentation all show the
navController
being passed down into the “Screen” Composables, and click handlers setup that call
navController.navigate()
. Without having tried it yet myself, this seems not great. Writing a Composable that requires a
navController
makes it less testable and less re-usable, no? Seems like it might be better to let the composables bubble up events and then handle them and do the navigation at the root level of the tree where the navController exists. But that too can get complicated because a “nav event” might need more than just a route to navigate to (for example, you might want to specify if it should pop the back stack, and how far to pop the back-stack, etc).
i

Ian Lake

11/10/2020, 3:41 PM
The Testing Navigation page does specifically call this out: https://developer.android.com/jetpack/compose/navigation#testing I would look at you really, really suspiciously if your screen is conditionally controlling where you pop up to, etc. If anything, it sounds like you have separate lambdas for separate actions
b

Bradleycorn

11/10/2020, 4:52 PM
Thanks @Ian Lake! Guess I should’ve kept reading past the Navigate with Arguments section 🙂
5 Views