mirror of
https://github.com/material-components/material-components-android.git
synced 2026-02-20 08:39:55 +08:00
Update vertical motion for TextInputLayout's error text.
Motion additions/updates in this change: - Added animation for error text's translation down - Updated durations and interpolators for the opacity in and out animations These changes roll forward changes that were previously rolled back because they broke screenshot tests. PiperOrigin-RevId: 158881906
This commit is contained in:
parent
06b88e84ad
commit
73cb135c15
@ -36,6 +36,8 @@
|
||||
<dimen name="design_tab_text_size">14sp</dimen>
|
||||
<dimen name="design_tab_text_size_2line">12sp</dimen>
|
||||
|
||||
<dimen name="design_textinput_error_translate_y">5dp</dimen>
|
||||
|
||||
<dimen name="design_snackbar_min_width">-1px</dimen>
|
||||
<dimen name="design_snackbar_max_width">-1px</dimen>
|
||||
<dimen name="design_snackbar_elevation">6dp</dimen>
|
||||
|
||||
@ -18,6 +18,8 @@ package android.support.design.widget;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
@ -110,17 +112,26 @@ import android.widget.TextView;
|
||||
*/
|
||||
public class TextInputLayout extends LinearLayout {
|
||||
|
||||
private static final int ANIMATION_DURATION = 200;
|
||||
// Duration for the label's scale up and down animations.
|
||||
private static final int LABEL_SCALE_ANIMATION_DURATION = 167;
|
||||
|
||||
// Duration for the error text's vertical translation animation.
|
||||
private static final int ERROR_TRANSLATE_Y_ANIMATION_DURATION = 250;
|
||||
|
||||
// Durations for the error text's opacity fade animations.
|
||||
private static final int ERROR_OPACITY_FADE_IN_ANIMATION_DURATION = 167;
|
||||
private static final int ERROR_OPACITY_FADE_OUT_ANIMATION_DURATION = 83;
|
||||
|
||||
private static final int INVALID_MAX_LENGTH = -1;
|
||||
|
||||
private static final String LOG_TAG = "TextInputLayout";
|
||||
|
||||
private final FrameLayout mInputFrame;
|
||||
private @Nullable Animator mErrorAnimator;
|
||||
EditText mEditText;
|
||||
|
||||
private final float mErrorTextTranslationYPx;
|
||||
|
||||
private boolean mHintEnabled;
|
||||
private CharSequence mHint;
|
||||
|
||||
@ -259,6 +270,9 @@ public class TextInputLayout extends LinearLayout {
|
||||
}
|
||||
|
||||
ViewCompat.setAccessibilityDelegate(this, new TextInputAccessibilityDelegate());
|
||||
|
||||
mErrorTextTranslationYPx =
|
||||
getResources().getDimensionPixelSize(R.dimen.design_textinput_error_translate_y);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -597,6 +611,9 @@ public class TextInputLayout extends LinearLayout {
|
||||
if (mErrorEnabled != enabled) {
|
||||
if (mErrorView != null) {
|
||||
mErrorView.animate().cancel();
|
||||
if (mErrorAnimator != null) {
|
||||
mErrorAnimator.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
@ -700,6 +717,9 @@ public class TextInputLayout extends LinearLayout {
|
||||
|
||||
// Cancel any on-going animation
|
||||
mErrorView.animate().cancel();
|
||||
if (mErrorAnimator != null) {
|
||||
mErrorAnimator.cancel();
|
||||
}
|
||||
|
||||
if (mErrorShown) {
|
||||
mErrorView.setText(error);
|
||||
@ -710,19 +730,35 @@ public class TextInputLayout extends LinearLayout {
|
||||
// If it's currently 100% show, we'll animate it from 0
|
||||
mErrorView.setAlpha(0f);
|
||||
}
|
||||
mErrorView
|
||||
.animate()
|
||||
.alpha(1f)
|
||||
.setDuration(ANIMATION_DURATION)
|
||||
.setInterpolator(AnimationUtils.LINEAR_OUT_SLOW_IN_INTERPOLATOR)
|
||||
.setListener(
|
||||
new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animator) {
|
||||
mErrorView.setVisibility(VISIBLE);
|
||||
}
|
||||
})
|
||||
.start();
|
||||
|
||||
ObjectAnimator errorOpacityAnimator = ObjectAnimator.ofFloat(mErrorView, ALPHA, 1f);
|
||||
ObjectAnimator errorTranslationYAnimator =
|
||||
ObjectAnimator.ofFloat(mErrorView, TRANSLATION_Y, -mErrorTextTranslationYPx, 0);
|
||||
|
||||
errorOpacityAnimator
|
||||
.setDuration(ERROR_OPACITY_FADE_IN_ANIMATION_DURATION)
|
||||
.setInterpolator(AnimationUtils.LINEAR_INTERPOLATOR);
|
||||
errorTranslationYAnimator
|
||||
.setDuration(ERROR_TRANSLATE_Y_ANIMATION_DURATION)
|
||||
.setInterpolator(AnimationUtils.LINEAR_OUT_SLOW_IN_INTERPOLATOR);
|
||||
|
||||
final AnimatorSet errorAnimatorSet = new AnimatorSet();
|
||||
mErrorAnimator = errorAnimatorSet;
|
||||
|
||||
errorAnimatorSet.playTogether(errorOpacityAnimator, errorTranslationYAnimator);
|
||||
errorAnimatorSet.addListener(
|
||||
new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mErrorAnimator = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
mErrorView.setVisibility(VISIBLE);
|
||||
}
|
||||
});
|
||||
errorAnimatorSet.start();
|
||||
} else {
|
||||
// Set alpha to 1f, just in case
|
||||
mErrorView.setAlpha(1f);
|
||||
@ -733,8 +769,8 @@ public class TextInputLayout extends LinearLayout {
|
||||
mErrorView
|
||||
.animate()
|
||||
.alpha(0f)
|
||||
.setDuration(ANIMATION_DURATION)
|
||||
.setInterpolator(AnimationUtils.FAST_OUT_LINEAR_IN_INTERPOLATOR)
|
||||
.setDuration(ERROR_OPACITY_FADE_OUT_ANIMATION_DURATION)
|
||||
.setInterpolator(AnimationUtils.LINEAR_INTERPOLATOR)
|
||||
.setListener(
|
||||
new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
@ -750,7 +786,6 @@ public class TextInputLayout extends LinearLayout {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateEditTextBackground();
|
||||
updateLabelState(animate);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user