Let's say I have a `Scaffold` and I show a snack...
# compose
d
Let's say I have a
Scaffold
and I show a snackbar by calling
scaffoldState.snackbarHostState.showSnackbar(...)
. The snackbar is shown above the fab. What can I do to make the snackbar move the fab up when it is shown and down when it disappears?
i
This is specifically one of the "Don't" examples from the Material guidelines: https://material.io/components/snackbars#behavior
Making sure visual elements don't move out from underneath users (say, as they're about to tap the FAB) is one of the key points to making a predictable UI
d
I understand, it just looks a bit unbalanced if the fab is aligned to the right side. Theres lots of space to the left of the fab when the snackbar appears above.
c
Could the snackbar be aligned at the bottom of the screen, starting at the left side of the screen and ending at the left edge of the fab?
d
@Ian Lake Why is the official example for the view based UI system showing exactly what should be avoided? Also it works out of the box in the view system. https://developer.android.com/training/snackbar/showing#coordinator (Figure 1)
blob thinking fast 1
a
That's the full-width snack bar in the old meterial design. The full-width snack bar pops up from the bottom of the screen so naturally it should push the fab up. You can find the old spec here. The design and the behavior of snack bars have been updated in the new design and what Ian said is an important reason I guess.
i
If you use the latest version of MDC, it should also match Compose
d
Alright, thanks for that clarification.
a
@Ian Lake FYI, on the M3 website under FAB implementation, it still states:
Note: If the
FloatingActionButton
is a child of a
CoordinatorLayout
, you get certain behaviors for free. It will automatically shift so that any displayed `Snackbar`s do not cover it, and will automatically hide when covered by an
AppBarLayout
or
BottomSheetBehavior
.
I'm not sure if this is true or not as I have not used the M3 version of MDC-Android. I definitely agree with the updated behavior to not move buttons like the FAB, but I also don't love how it looks to have the snackbar appear above the FAB. 😕
i
Yeah, that hasn't been the case with a
CoordinatorLayout
for years at this point (and there's no Material3 version of
CoordinatorLayout
). I'd tap the 'Feedback' button on the bottom to report any inaccuracies directly to the right people
👍 1