@@ -870,6 +870,8 @@ public static class Behavior extends HideBottomViewOnScrollBehavior<BottomAppBar
870870
871871 private WeakReference <BottomAppBar > viewRef ;
872872
873+ private int originalBottomMargin ;
874+
873875 private final OnLayoutChangeListener fabLayoutListener =
874876 new OnLayoutChangeListener () {
875877 @ Override
@@ -897,28 +899,24 @@ public void onLayoutChange(
897899 int height = fabContentRect .height ();
898900
899901 // Set the cutout diameter based on the height of the fab.
900- if (!child .setFabDiameter (height )) {
901- // The size of the fab didn't change so return early.
902- return ;
903- }
902+ child .setFabDiameter (height );
904903
905904 CoordinatorLayout .LayoutParams fabLayoutParams =
906905 (CoordinatorLayout .LayoutParams ) v .getLayoutParams ();
907906
908- // Set the bottomMargin of the fab if it is 0dp. This adds space below the fab if the
909- // BottomAppBar is hidden.
910- if (fabLayoutParams . bottomMargin == 0 ) {
907+ // Manage the bottomMargin of the fab if it wasn't explicitly set to something. This
908+ // adds space below the fab if the BottomAppBar is hidden.
909+ if (originalBottomMargin == 0 ) {
911910 // Extra padding is added for the fake shadow on API < 21. Ensure we don't add too
912911 // much space by removing that extra padding.
913- int bottomShadowPadding = (fab .getMeasuredHeight () - fabContentRect . height () ) / 2 ;
912+ int bottomShadowPadding = (fab .getMeasuredHeight () - height ) / 2 ;
914913 int bottomMargin =
915914 child
916915 .getResources ()
917916 .getDimensionPixelOffset (R .dimen .mtrl_bottomappbar_fab_bottom_margin );
918- // At least be tall enough to be above the bottom insets, otherwise set some space
919- // ignoring any shadow padding.
920- fabLayoutParams .bottomMargin =
921- Math .max (child .getBottomInset (), bottomMargin - bottomShadowPadding );
917+ // Should be moved above the bottom insets with space ignoring any shadow padding.
918+ int minBottomMargin = bottomMargin - bottomShadowPadding ;
919+ fabLayoutParams .bottomMargin = child .getBottomInset () + minBottomMargin ;
922920 }
923921 }
924922 };
@@ -945,6 +943,10 @@ public boolean onLayoutChild(
945943 (CoordinatorLayout .LayoutParams ) dependentView .getLayoutParams ();
946944 fabLayoutParams .anchorGravity = Gravity .CENTER | Gravity .TOP ;
947945
946+ // Keep track of the original bottom margin for the fab. We will manage the margin if
947+ // nothing was set.
948+ originalBottomMargin = fabLayoutParams .bottomMargin ;
949+
948950 if (dependentView instanceof FloatingActionButton ) {
949951 FloatingActionButton fab = ((FloatingActionButton ) dependentView );
950952
0 commit comments