Hello guys I am working on refactoring my app code...
# compose
q
Hello guys I am working on refactoring my app code, I had a single top app bar using it for all screens, the question is shall i need to make top app bar for each screen ? just to handle the actions click or let it single one but I don't have any idea how I can get any data from my screen when I click on any icon in actions... Like if I had a share button on my Top App bar how should I pass the content I want to share to my Top App? ( for now I am handling it with a trick but I need to know the best practice. now in android dosent show the case I am talking about )
c
We usually define a TopAppBar as a standalone Composable somewhere where every screen can access it, and add it to each screen. (Or to a ScreenScaffold, but that is basically the same) You could define a “slot” for action icons, and then you are able to add the share button on the Screen from where you want to share something, and then handle the share event on your screen directly
c
I end up putting a top app bar on every screen. It allows me to do cool things like scrolling animations and stuff. the only thing i typically share is the bottom tab navigation.
q
I already made my TopAppBar as a component, you mean to start using this component on each screen right?
✔️ 2
yeah, I see I just wanted to confirm that this is a good approach
c
yeah. ive done that on like 5 apps. never had a problem. and then the one off cases of using a large top app bar, or doing an animation, or not showing an app bar on a certain screen are really easy.
🙏 1
✔️ 1
q
Yeah, I used it as a single one and I really struggled with this case how to let my screen communicate with the Top App Bar component which is on my NavHost, it was like a maze....