Skip to content

Commit

Permalink
[ExtendedFloatingActionButton] Add a method to ExtendedFloatingAction…
Browse files Browse the repository at this point in the history
…Button to enable/disable animations.

PiperOrigin-RevId: 688229664
  • Loading branch information
imhappi authored and kendrickumstattd committed Oct 22, 2024
1 parent 9fe362f commit 31fa412
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Rect;
import android.text.TextUtils;
import android.util.AttributeSet;
Expand Down Expand Up @@ -103,6 +104,8 @@ public class ExtendedFloatingActionButton extends MaterialButton implements Atta
/** Strategy to extend the FAB. */
private static final int EXTEND = 3;

private boolean animationEnabled = true;

/**
* The strategy type determines what motion strategy to apply on the FAB.
*
Expand Down Expand Up @@ -915,8 +918,25 @@ private boolean isOrWillBeHidden() {
}
}

/**
* Set whether or not animations are enabled.
*
* @hide
*/
@RestrictTo(LIBRARY_GROUP)
public void setAnimationEnabled(boolean animationEnabled) {
this.animationEnabled = animationEnabled;
}

/** Return whether or not animations are enabled. */
public boolean isAnimationEnabled() {
return animationEnabled;
}

private boolean shouldAnimateVisibilityChange() {
return (isLaidOut() || (!isOrWillBeShown() && animateShowBeforeLayout)) && !isInEditMode();
return animationEnabled
&& (isLaidOut() || (!isOrWillBeShown() && animateShowBeforeLayout))
&& !isInEditMode();
}

/**
Expand Down Expand Up @@ -1332,6 +1352,17 @@ public void performNow() {
}
layoutParams.width = size.getLayoutParams().width;
layoutParams.height = size.getLayoutParams().height;

if (extending) { // extending
silentlyUpdateTextColor(originalTextCsl);
} else if (getText() != null && getText() != "") { // shrinking
// We only update the text to transparent if it exists, otherwise, updating the
// text color to transparent affects the elevation of the view.
// It's okay for the text to be set afterwards and not be transparent, as it is cut off
// by forcing the layout param dimens.
silentlyUpdateTextColor(ColorStateList.valueOf(Color.TRANSPARENT));
}

setPaddingRelative(
size.getPaddingStart(),
getPaddingTop(),
Expand Down

0 comments on commit 31fa412

Please sign in to comment.