mirror of
https://github.com/material-components/material-components-android.git
synced 2026-02-20 08:39:55 +08:00
am c2ca8014: am 402b0e23: am c58757f9: am 7c6948ec: am 39d1d2d3: FloatingActionButton animation fixes
* commit 'c2ca8014857698bffcab89e5e50d072ecab65312': FloatingActionButton animation fixes GitOrigin-RevId=9627255824e227213beeedfcde00109c46d7d3bf PiperOrigin-RevId: 140549411
This commit is contained in:
parent
28b86ba6c3
commit
74c3dff7bb
@ -158,8 +158,8 @@ class FloatingActionButtonEclairMr1 extends FloatingActionButtonImpl {
|
||||
|
||||
@Override
|
||||
void hide() {
|
||||
if (mIsHiding) {
|
||||
// There is currently an hide animation running, return
|
||||
if (mIsHiding || mView.getVisibility() != View.VISIBLE) {
|
||||
// A hide animation is in progress, or we're already hidden. Skip the call
|
||||
return;
|
||||
}
|
||||
|
||||
@ -184,11 +184,17 @@ class FloatingActionButtonEclairMr1 extends FloatingActionButtonImpl {
|
||||
|
||||
@Override
|
||||
void show() {
|
||||
Animation anim = android.view.animation.AnimationUtils.loadAnimation(
|
||||
mView.getContext(), R.anim.design_fab_in);
|
||||
anim.setDuration(SHOW_HIDE_ANIM_DURATION);
|
||||
anim.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
|
||||
mView.startAnimation(anim);
|
||||
if (mView.getVisibility() != View.VISIBLE || mIsHiding) {
|
||||
// If the view is not visible, or is visible and currently being hidden, run
|
||||
// the show animation
|
||||
mView.clearAnimation();
|
||||
mView.setVisibility(View.VISIBLE);
|
||||
Animation anim = android.view.animation.AnimationUtils.loadAnimation(
|
||||
mView.getContext(), R.anim.design_fab_in);
|
||||
anim.setDuration(SHOW_HIDE_ANIM_DURATION);
|
||||
anim.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
|
||||
mView.startAnimation(anim);
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePadding() {
|
||||
|
||||
@ -18,6 +18,7 @@ package android.support.design.widget;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.view.View;
|
||||
|
||||
class FloatingActionButtonHoneycombMr1 extends FloatingActionButtonEclairMr1 {
|
||||
@ -30,44 +31,67 @@ class FloatingActionButtonHoneycombMr1 extends FloatingActionButtonEclairMr1 {
|
||||
|
||||
@Override
|
||||
void hide() {
|
||||
if (mIsHiding) {
|
||||
// A hide animation is in progress, skip the call
|
||||
if (mIsHiding || mView.getVisibility() != View.VISIBLE) {
|
||||
// A hide animation is in progress, or we're already hidden. Skip the call
|
||||
return;
|
||||
}
|
||||
|
||||
mView.animate()
|
||||
.scaleX(0f)
|
||||
.scaleY(0f)
|
||||
.alpha(0f)
|
||||
.setDuration(SHOW_HIDE_ANIM_DURATION)
|
||||
.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR)
|
||||
.setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
mIsHiding = true;
|
||||
}
|
||||
if (!ViewCompat.isLaidOut(mView) || mView.isInEditMode()) {
|
||||
// If the view isn't laid out, or we're in the editor, don't run the animation
|
||||
mView.setVisibility(View.GONE);
|
||||
} else {
|
||||
mView.animate()
|
||||
.scaleX(0f)
|
||||
.scaleY(0f)
|
||||
.alpha(0f)
|
||||
.setDuration(SHOW_HIDE_ANIM_DURATION)
|
||||
.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR)
|
||||
.setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
mIsHiding = true;
|
||||
mView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
mIsHiding = false;
|
||||
}
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
mIsHiding = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mIsHiding = false;
|
||||
mView.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mIsHiding = false;
|
||||
mView.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void show() {
|
||||
mView.animate()
|
||||
.scaleX(1f)
|
||||
.scaleY(1f)
|
||||
.alpha(1f)
|
||||
.setDuration(SHOW_HIDE_ANIM_DURATION)
|
||||
.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR)
|
||||
.setListener(null);
|
||||
if (mView.getVisibility() != View.VISIBLE) {
|
||||
if (ViewCompat.isLaidOut(mView) && !mView.isInEditMode()) {
|
||||
mView.setAlpha(0f);
|
||||
mView.setScaleY(0f);
|
||||
mView.setScaleX(0f);
|
||||
mView.animate()
|
||||
.scaleX(1f)
|
||||
.scaleY(1f)
|
||||
.alpha(1f)
|
||||
.setDuration(SHOW_HIDE_ANIM_DURATION)
|
||||
.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR)
|
||||
.setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
mView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mView.setVisibility(View.VISIBLE);
|
||||
mView.setAlpha(1f);
|
||||
mView.setScaleY(1f);
|
||||
mView.setScaleX(1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -239,13 +239,7 @@ public class FloatingActionButton extends ImageView {
|
||||
* <p>This method will animate it the button show if the view has already been laid out.</p>
|
||||
*/
|
||||
public void show() {
|
||||
if (getVisibility() == VISIBLE) {
|
||||
return;
|
||||
}
|
||||
setVisibility(VISIBLE);
|
||||
if (ViewCompat.isLaidOut(this)) {
|
||||
mImpl.show();
|
||||
}
|
||||
mImpl.show();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -253,14 +247,7 @@ public class FloatingActionButton extends ImageView {
|
||||
* <p>This method will animate the button hide if the view has already been laid out.</p>
|
||||
*/
|
||||
public void hide() {
|
||||
if (getVisibility() != VISIBLE) {
|
||||
return;
|
||||
}
|
||||
if (ViewCompat.isLaidOut(this) && !isInEditMode()) {
|
||||
mImpl.hide();
|
||||
} else {
|
||||
setVisibility(GONE);
|
||||
}
|
||||
mImpl.hide();
|
||||
}
|
||||
|
||||
final int getSizeDimension() {
|
||||
@ -338,7 +325,6 @@ public class FloatingActionButton extends ImageView {
|
||||
private static final boolean SNACKBAR_BEHAVIOR_ENABLED = Build.VERSION.SDK_INT >= 11;
|
||||
|
||||
private Rect mTmpRect;
|
||||
private float mTranslationY;
|
||||
|
||||
@Override
|
||||
public boolean layoutDependsOn(CoordinatorLayout parent,
|
||||
@ -366,10 +352,15 @@ public class FloatingActionButton extends ImageView {
|
||||
if (dependency instanceof Snackbar.SnackbarLayout) {
|
||||
// If the removed view is a SnackbarLayout, we will animate back to our normal
|
||||
// position
|
||||
ViewCompat.animate(child)
|
||||
.translationY(0f)
|
||||
.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR)
|
||||
.setListener(null);
|
||||
if (ViewCompat.getTranslationY(child) != 0f) {
|
||||
ViewCompat.animate(child)
|
||||
.translationY(0f)
|
||||
.scaleX(1f)
|
||||
.scaleY(1f)
|
||||
.alpha(1f)
|
||||
.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR)
|
||||
.setListener(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -408,13 +399,7 @@ public class FloatingActionButton extends ImageView {
|
||||
}
|
||||
|
||||
final float translationY = getFabTranslationYForSnackbar(parent, fab);
|
||||
if (translationY != mTranslationY) {
|
||||
// First, cancel any current animation
|
||||
ViewCompat.animate(fab).cancel();
|
||||
// Else we'll set use setTranslationY
|
||||
ViewCompat.setTranslationY(fab, translationY);
|
||||
mTranslationY = translationY;
|
||||
}
|
||||
ViewCompat.setTranslationY(fab, translationY);
|
||||
}
|
||||
|
||||
private float getFabTranslationYForSnackbar(CoordinatorLayout parent,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user