Skip to content

Commit 31fa412

Browse files
imhappikendrickumstattd
authored andcommitted
[ExtendedFloatingActionButton] Add a method to ExtendedFloatingActionButton to enable/disable animations.
PiperOrigin-RevId: 688229664
1 parent 9fe362f commit 31fa412

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

lib/java/com/google/android/material/floatingactionbutton/ExtendedFloatingActionButton.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import android.content.Context;
3333
import android.content.res.ColorStateList;
3434
import android.content.res.TypedArray;
35+
import android.graphics.Color;
3536
import android.graphics.Rect;
3637
import android.text.TextUtils;
3738
import android.util.AttributeSet;
@@ -103,6 +104,8 @@ public class ExtendedFloatingActionButton extends MaterialButton implements Atta
103104
/** Strategy to extend the FAB. */
104105
private static final int EXTEND = 3;
105106

107+
private boolean animationEnabled = true;
108+
106109
/**
107110
* The strategy type determines what motion strategy to apply on the FAB.
108111
*
@@ -915,8 +918,25 @@ private boolean isOrWillBeHidden() {
915918
}
916919
}
917920

921+
/**
922+
* Set whether or not animations are enabled.
923+
*
924+
* @hide
925+
*/
926+
@RestrictTo(LIBRARY_GROUP)
927+
public void setAnimationEnabled(boolean animationEnabled) {
928+
this.animationEnabled = animationEnabled;
929+
}
930+
931+
/** Return whether or not animations are enabled. */
932+
public boolean isAnimationEnabled() {
933+
return animationEnabled;
934+
}
935+
918936
private boolean shouldAnimateVisibilityChange() {
919-
return (isLaidOut() || (!isOrWillBeShown() && animateShowBeforeLayout)) && !isInEditMode();
937+
return animationEnabled
938+
&& (isLaidOut() || (!isOrWillBeShown() && animateShowBeforeLayout))
939+
&& !isInEditMode();
920940
}
921941

922942
/**
@@ -1332,6 +1352,17 @@ public void performNow() {
13321352
}
13331353
layoutParams.width = size.getLayoutParams().width;
13341354
layoutParams.height = size.getLayoutParams().height;
1355+
1356+
if (extending) { // extending
1357+
silentlyUpdateTextColor(originalTextCsl);
1358+
} else if (getText() != null && getText() != "") { // shrinking
1359+
// We only update the text to transparent if it exists, otherwise, updating the
1360+
// text color to transparent affects the elevation of the view.
1361+
// It's okay for the text to be set afterwards and not be transparent, as it is cut off
1362+
// by forcing the layout param dimens.
1363+
silentlyUpdateTextColor(ColorStateList.valueOf(Color.TRANSPARENT));
1364+
}
1365+
13351366
setPaddingRelative(
13361367
size.getPaddingStart(),
13371368
getPaddingTop(),

0 commit comments

Comments
 (0)