Skip to content

Commit

Permalink
[BottomAppBar] Add attribute to remove embedded FAB elevation
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 457084450
  • Loading branch information
imhappi authored and raajkumars committed Jun 27, 2022
1 parent cd37b91 commit f2423de
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/components/BottomAppBar.md
Expand Up @@ -239,6 +239,7 @@ Element | Attribute | Related
**Cradle rounded corner radius** | `app:fabCradleRoundedCornerRadius` | `setFabCradleRoundedCornerRadius`<br>`getFabCradleRoundedCornerRadius` | `4dp`
**Cradle vertical offset** | `app:fabCradleVerticalOffset` | `setCradleVerticalOffset`<br>`getCradleVerticalOffset` | `12dp`
**End margin** | `app:fabAlignmentModeEndMargin` | `setFabAlignmentModeEndMargin` <br> `getFabAlignmentModeEndMargin` | N/A
**Embedded elevation** | `app:removeEmbeddedFabElevation` | N/A | `true`

See the
[FAB documentation](https://github.com/material-components/material-components-android/tree/master/docs/components/FloatingActionButton.md)
Expand Down
Expand Up @@ -184,7 +184,6 @@ public class BottomAppBar extends Toolbar implements AttachedBehavior {

@Nullable private Animator modeAnimator;
@Nullable private Animator menuAnimator;
@MenuAlignmentMode private int menuAlignmentMode;
@FabAlignmentMode private int fabAlignmentMode;
@FabAnimationMode private int fabAnimationMode;
@FabAnchorMode private int fabAnchorMode;
Expand All @@ -195,6 +194,8 @@ public class BottomAppBar extends Toolbar implements AttachedBehavior {
private final int fabOffsetEndMode;
@Px private int fabAlignmentModeEndMargin;

@MenuAlignmentMode private int menuAlignmentMode;
private final boolean removeEmbeddedFabElevation;
private boolean hideOnScroll;
private final boolean paddingBottomSystemWindowInsets;
private final boolean paddingLeftSystemWindowInsets;
Expand Down Expand Up @@ -324,6 +325,9 @@ public BottomAppBar(@NonNull Context context, @Nullable AttributeSet attrs, int
fabAnimationMode =
a.getInt(R.styleable.BottomAppBar_fabAnimationMode, FAB_ANIMATION_MODE_SCALE);
fabAnchorMode = a.getInt(R.styleable.BottomAppBar_fabAnchorMode, FAB_ANCHOR_MODE_CRADLE);
removeEmbeddedFabElevation =
a.getBoolean(R.styleable.BottomAppBar_removeEmbeddedFabElevation, true);

menuAlignmentMode =
a.getInt(R.styleable.BottomAppBar_menuAlignmentMode, MENU_ALIGNMENT_MODE_AUTO);
hideOnScroll = a.getBoolean(R.styleable.BottomAppBar_hideOnScroll, false);
Expand Down Expand Up @@ -1375,6 +1379,10 @@ public boolean onLayoutChild(

if (dependentView instanceof FloatingActionButton) {
FloatingActionButton fab = ((FloatingActionButton) dependentView);
if (child.fabAnchorMode == FAB_ANCHOR_MODE_EMBED && child.removeEmbeddedFabElevation) {
ViewCompat.setElevation(fab, 0);
fab.setCompatElevation(0);
}

// TODO (b/185233196): Update to use FABs default animator with motion theming.
// If there is no motion spec set on the anchored fab, set one which scales the fab to
Expand Down
Expand Up @@ -25,6 +25,7 @@
<public name="fabAlignmentModeEndMargin" type="attr"/>
<public name="menuAlignmentMode" type="attr"/>
<public name="hideOnScroll" type="attr"/>
<public name="removeEmbeddedFabElevation" type="attr"/>
<public name="Widget.MaterialComponents.BottomAppBar" type="style"/>
<public name="Widget.MaterialComponents.BottomAppBar.Colored" type="style"/>
<public name="Widget.MaterialComponents.BottomAppBar.PrimarySurface" type="style"/>
Expand Down
Expand Up @@ -52,6 +52,8 @@
<attr name="fabCradleVerticalOffset" format="dimension"/>
<!-- The end margin of the fab when the fab is end-aligned. -->
<attr name="fabAlignmentModeEndMargin" format="dimension"/>
<!-- Whether or not to remove elevation for embedded fabs in the bottom app bar. -->
<attr name="removeEmbeddedFabElevation" format="boolean"/>
<!-- Whether the BottomAppBar should hide when a NestedScrollView is scrolled. -->
<attr name="hideOnScroll" format="boolean"/>
<!-- Whether the BottomAppBar should apply padding to be above the bottom window insets. -->
Expand Down
Expand Up @@ -61,7 +61,6 @@
<item name="fabCradleVerticalOffset">
@dimen/m3_bottomappbar_fab_cradle_vertical_offset
</item>

<item name="elevation">@dimen/m3_sys_elevation_level2</item>

<item name="backgroundTint">?attr/colorSurface</item>
Expand Down

0 comments on commit f2423de

Please sign in to comment.