I remember in the earlier days of Compose seeing a...
# compose
j
I remember in the earlier days of Compose seeing a bunch of sample apps with a
Scaffold
at (or near) the top of their hierarchy, meaning each individual “screen” was wrapped by one “grandparent” Scaffold, which meant you would have a single source of controlling a drawer layout and a snackbar host. These days I don’t see that pattern as much, and the pattern is more like one Scaffold for each screen. Which of these is the recommended way of doing things? My guess is the second one (many Scaffolds) is the way but I wanted to hear thoughts from others 🙏
s
A scaffold per screen sounds hard when animating around, the scaffold will also animate out and a new out with the same content will come in, sounds a bit odd no?
j
I’ve worked on apps that have a single Scaffold for the whole app and apps that have many Scaffolds and I didn’t come across major issues with regards to navigation.. but I came across this recently:
f
another issue with multiple scaffolds is handling snackbars. Say, for instance, you are in an edit screen and you back out and want to show an Undo snackbar - you have to pass that responsibility to whichever screen you came from, instead of being able to handle this at the edit screen
z
If you use a Scaffold for each screen, your snackbars will automatically behave correctly. For example, if youre using a bottomBar, your snackbar is automatically offset so that its shown "beside" it, rather than on top of it!
b
I generally prefer that each screen manages its own “chrome” such as toolbars. The content of the toolbar including the presence (or lack) of a back button, the title, and any actions are typically relevant to that particular screen, so the screen should own it. We have also run into situations in our app where specific screens will want to show a different colored header/toolbar, and in some cases that needs to be behind a transparent status bar. Managing all of that in a common location gets messy and prone to falling into incorrect states. That’s true for a non-compose world too.