1616
1717package com .google .android .material .behavior ;
1818
19+ import com .google .android .material .R ;
20+
1921import static androidx .annotation .RestrictTo .Scope .LIBRARY_GROUP ;
2022
2123import android .animation .Animator ;
3537import androidx .coordinatorlayout .widget .CoordinatorLayout .Behavior ;
3638import androidx .core .view .ViewCompat ;
3739import com .google .android .material .animation .AnimationUtils ;
40+ import com .google .android .material .motion .MotionUtils ;
3841import java .util .LinkedHashSet ;
3942
4043/**
@@ -63,8 +66,16 @@ public interface OnScrollStateChangedListener {
6366 private final LinkedHashSet <OnScrollStateChangedListener > onScrollStateChangedListeners =
6467 new LinkedHashSet <>();
6568
66- protected static final int ENTER_ANIMATION_DURATION = 225 ;
67- protected static final int EXIT_ANIMATION_DURATION = 175 ;
69+ private static final int DEFAULT_ENTER_ANIMATION_DURATION_MS = 225 ;
70+ private static final int DEFAULT_EXIT_ANIMATION_DURATION_MS = 175 ;
71+ private static final int ENTER_ANIM_DURATION_ATTR = R .attr .motionDurationLong2 ;
72+ private static final int EXIT_ANIM_DURATION_ATTR = R .attr .motionDurationMedium4 ;
73+ private static final int ENTER_EXIT_ANIM_EASING_ATTR = R .attr .motionEasingEmphasizedInterpolator ;
74+
75+ private final int enterAnimDuration ;
76+ private final int exitAnimDuration ;
77+ private final TimeInterpolator enterAnimInterpolator ;
78+ private final TimeInterpolator exitAnimInterpolator ;
6879
6980 /** State of the bottom view when it's scrolled down. */
7081 public static final int STATE_SCROLLED_DOWN = 1 ;
@@ -88,10 +99,21 @@ public interface OnScrollStateChangedListener {
8899 private int additionalHiddenOffsetY = 0 ;
89100 @ Nullable private ViewPropertyAnimator currentAnimator ;
90101
91- public HideBottomViewOnScrollBehavior () {}
92-
93102 public HideBottomViewOnScrollBehavior (Context context , AttributeSet attrs ) {
94103 super (context , attrs );
104+
105+ enterAnimDuration =
106+ MotionUtils .resolveThemeDuration (
107+ context , ENTER_ANIM_DURATION_ATTR , DEFAULT_ENTER_ANIMATION_DURATION_MS );
108+ exitAnimDuration =
109+ MotionUtils .resolveThemeDuration (
110+ context , EXIT_ANIM_DURATION_ATTR , DEFAULT_EXIT_ANIMATION_DURATION_MS );
111+ enterAnimInterpolator =
112+ MotionUtils .resolveThemeInterpolator (
113+ context , ENTER_EXIT_ANIM_EASING_ATTR , AnimationUtils .LINEAR_OUT_SLOW_IN_INTERPOLATOR );
114+ exitAnimInterpolator =
115+ MotionUtils .resolveThemeInterpolator (
116+ context , ENTER_EXIT_ANIM_EASING_ATTR , AnimationUtils .FAST_OUT_LINEAR_IN_INTERPOLATOR );
95117 }
96118
97119 @ Override
@@ -177,11 +199,7 @@ public void slideUp(@NonNull V child, boolean animate) {
177199 updateCurrentState (child , STATE_SCROLLED_UP );
178200 int targetTranslationY = 0 ;
179201 if (animate ) {
180- animateChildTo (
181- child ,
182- targetTranslationY ,
183- ENTER_ANIMATION_DURATION ,
184- AnimationUtils .LINEAR_OUT_SLOW_IN_INTERPOLATOR );
202+ animateChildTo (child , targetTranslationY , enterAnimDuration , enterAnimInterpolator );
185203 } else {
186204 child .setTranslationY (targetTranslationY );
187205 }
@@ -218,11 +236,7 @@ public void slideDown(@NonNull V child, boolean animate) {
218236 updateCurrentState (child , STATE_SCROLLED_DOWN );
219237 int targetTranslationY = height + additionalHiddenOffsetY ;
220238 if (animate ) {
221- animateChildTo (
222- child ,
223- targetTranslationY ,
224- EXIT_ANIMATION_DURATION ,
225- AnimationUtils .FAST_OUT_LINEAR_IN_INTERPOLATOR );
239+ animateChildTo (child , targetTranslationY , exitAnimDuration , exitAnimInterpolator );
226240 } else {
227241 child .setTranslationY (targetTranslationY );
228242 }
0 commit comments