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

Travis Griggs

02/23/2023, 11:23 PM
I have a tab bar where each element selects a different route in a NavController. There are two approaches I can take to architecting this coupling: 1. pass the navController into the TabBar which in turn passes it to the TabElements which finally configures its click action to set the route of the NavController 2. Have the TabBar take a unary closure which fires when an element is selected, and wire that closure at the top composable where the NavHost and the TabBar are both created I prototyped it real quick and did #1. But I think I would like #2 better, because it isolates the details of what my tabbar/elements do better. And I think from what I've read of various always-evolving compose documents, this is encouraged there as well. Does this sound correct?
2️⃣ 5
i

Ian Lake

02/23/2023, 11:29 PM
#2 certainly aligns with the idea of a slot API pattern, which works extremely well for cases like this: https://chris.banes.me/posts/slotting-in-with-compose-ui/