Skip to content

Commit 3a1aa13

Browse files
committed
[FloatingActionButton] Use the current labelOpacity as the initial animation value
1 parent 8ec6b77 commit 3a1aa13

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import android.view.ViewGroup.LayoutParams;
4444
import android.view.ViewGroup.MarginLayoutParams;
4545
import androidx.annotation.AnimatorRes;
46+
import androidx.annotation.ColorInt;
4647
import androidx.annotation.IntDef;
4748
import androidx.annotation.NonNull;
4849
import androidx.annotation.Nullable;
@@ -460,6 +461,15 @@ private void saveOriginalTextCsl() {
460461
originalTextCsl = getTextColors();
461462
}
462463

464+
ColorStateList getOriginalTextColor() {
465+
return originalTextCsl;
466+
}
467+
468+
@ColorInt
469+
int getCurrentOriginalTextColor() {
470+
return originalTextCsl.getColorForState(getDrawableState(), 0);
471+
}
472+
463473
/**
464474
* Update the text color without affecting the original, client-set color.
465475
*/
@@ -1417,7 +1427,9 @@ public AnimatorSet createAnimator() {
14171427

14181428
if (spec.hasPropertyValues("labelOpacity")) {
14191429
PropertyValuesHolder[] labelOpacityValues = spec.getPropertyValues("labelOpacity");
1420-
float startValue = extending ? 0F : 1F;
1430+
final int originalAlpha = Color.alpha(getCurrentOriginalTextColor());
1431+
final int currentAlpha = Color.alpha(getCurrentTextColor());
1432+
float startValue = originalAlpha != 0 ? (float) currentAlpha / originalAlpha : 0f;
14211433
float endValue = extending ? 1F : 0F;
14221434
labelOpacityValues[0].setFloatValues(startValue, endValue);
14231435
spec.setPropertyValues("labelOpacity", labelOpacityValues);

0 commit comments

Comments
 (0)