Skip to content

Commit fdd8dae

Browse files
committed
[BottomAppBar][BottomNavigationView] Update motion specs for show/hide bar
PiperOrigin-RevId: 469291824
1 parent c7a3d5e commit fdd8dae

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

lib/java/com/google/android/material/behavior/HideBottomViewOnScrollBehavior.java

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.google.android.material.behavior;
1818

19+
import com.google.android.material.R;
20+
1921
import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
2022

2123
import android.animation.Animator;
@@ -35,6 +37,7 @@
3537
import androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior;
3638
import androidx.core.view.ViewCompat;
3739
import com.google.android.material.animation.AnimationUtils;
40+
import com.google.android.material.motion.MotionUtils;
3841
import 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
}

lib/java/com/google/android/material/bottomappbar/BottomAppBar.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ public void setSubtitle(CharSequence subtitle) {
12651265
@Override
12661266
public Behavior getBehavior() {
12671267
if (behavior == null) {
1268-
behavior = new Behavior();
1268+
behavior = new Behavior(getContext());
12691269
}
12701270
return behavior;
12711271
}
@@ -1376,11 +1376,11 @@ public void onLayoutChange(
13761376
}
13771377
};
13781378

1379-
public Behavior() {
1380-
fabContentRect = new Rect();
1379+
public Behavior(@NonNull Context context) {
1380+
this(context, null);
13811381
}
13821382

1383-
public Behavior(Context context, AttributeSet attrs) {
1383+
public Behavior(@NonNull Context context, @Nullable AttributeSet attrs) {
13841384
super(context, attrs);
13851385
fabContentRect = new Rect();
13861386
}

0 commit comments

Comments
 (0)