Question about snackbars. If I have a root level Scaffold, and each of my screens also uses a scaffold... I'm starting to think I should send all snackbars to the root level scaffold. Maybe there's no right/wrong way to do this, but I guess thinking of snackbars as like an app level notification (like a toast), then just punting to the root kinda sorta makes sense?
12/03/2021, 4:53 PM
that's what I was thinking too.
What I was wondering is :
• the best way to send the info from any destination ? (
It could be a shared viewmodel between all destinations ?, or a "singleton" like component injected in each viewmodel or passed through the composable)
• how to handle snackbar action
12/03/2021, 4:56 PM
I'm going to try the root based scaffold for just Snackbars basically. And it'll wrap my NavHost (navigation component). I'll see if i hate it. 😄
12/03/2021, 5:04 PM
Compose snackbars are aggressively simple; if anything I think we sort of did a disservice by wrapping up a default implementation of the snackbar host in Scaffold because it makes people think it's more complicated than it really is or some kind of special case
Do it the way that matches the design of your app and hoist the state up to the common point where things that need to report messages into it can access it. The snackbar state has no activity or composition-scoped dependencies; I've written apps where I declared one as a top-level global
somewhere in the app
use your favorite DI scoping mechanism if you must. 🙂
12/03/2021, 5:40 PM
Thanks adam. Are you also saying that we don't actually need a scaffold?
That also makes sense to me because I might not want to introduce a scaffold around my navHost, and instead build a smaller (better defined) App composable which can host a snackbar.
12/03/2021, 5:57 PM
The Scaffold is useful because it can help in some mutual positioning of elements, but it's not the only thing capable of doing so
12/03/2021, 5:59 PM
Hm. So I guess I can just build a top level composable that can also handle a scaffold if I don't necesarily need the out of box repositioning feature.
but I probably want to consider using it so I don't do want twitter did and have snackbars show under a FAB. LOL