Skip to content

Commit

Permalink
[TabLayout] Update motion attributes for tab layout
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 468736364
  • Loading branch information
imhappi authored and leticiarossi committed Aug 22, 2022
1 parent 44cc9b7 commit d1c5a52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/java/com/google/android/material/tabs/TabLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static com.google.android.material.animation.AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR;
import static com.google.android.material.theme.overlay.MaterialThemeOverlay.wrap;

import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.content.Context;
Expand Down Expand Up @@ -94,6 +95,7 @@
import com.google.android.material.drawable.DrawableUtils;
import com.google.android.material.internal.ThemeEnforcement;
import com.google.android.material.internal.ViewUtils;
import com.google.android.material.motion.MotionUtils;
import com.google.android.material.resources.MaterialResources;
import com.google.android.material.ripple.RippleUtils;
import com.google.android.material.shape.MaterialShapeDrawable;
Expand Down Expand Up @@ -480,6 +482,7 @@ public interface BaseOnTabSelectedListener<T extends Tab> {
boolean unboundedRipple;

private TabIndicatorInterpolator tabIndicatorInterpolator;
private final TimeInterpolator tabIndicatorTimeInterpolator;

@Nullable private BaseOnTabSelectedListener selectedListener;

Expand Down Expand Up @@ -607,6 +610,9 @@ public TabLayout(@NonNull Context context, @Nullable AttributeSet attrs, int def

tabIndicatorAnimationDuration =
a.getInt(R.styleable.TabLayout_tabIndicatorAnimationDuration, ANIMATION_DURATION);
tabIndicatorTimeInterpolator =
MotionUtils.resolveThemeInterpolator(
context, R.attr.motionEasingEmphasizedInterpolator, FAST_OUT_SLOW_IN_INTERPOLATOR);

requestedTabMinWidth =
a.getDimensionPixelSize(R.styleable.TabLayout_tabMinWidth, INVALID_WIDTH);
Expand Down Expand Up @@ -1818,7 +1824,7 @@ private void animateToTab(int newPosition) {
private void ensureScrollAnimator() {
if (scrollAnimator == null) {
scrollAnimator = new ValueAnimator();
scrollAnimator.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
scrollAnimator.setInterpolator(tabIndicatorTimeInterpolator);
scrollAnimator.setDuration(tabIndicatorAnimationDuration);
scrollAnimator.addUpdateListener(
new ValueAnimator.AnimatorUpdateListener() {
Expand Down Expand Up @@ -3238,7 +3244,7 @@ public void onAnimationUpdate(@NonNull ValueAnimator valueAnimator) {
if (recreateAnimation) {
// Create & start a new indicatorAnimator.
ValueAnimator animator = indicatorAnimator = new ValueAnimator();
animator.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
animator.setInterpolator(tabIndicatorTimeInterpolator);
animator.setDuration(duration);
animator.setFloatValues(0F, 1F);
animator.addUpdateListener(updateListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<item name="tabIndicatorColor">?attr/colorPrimary</item>
<item name="tabRippleColor">@color/m3_tabs_ripple_color</item>
<item name="tabIndicatorFullWidth">false</item>
<item name="tabIndicatorAnimationDuration">?attr/motionDurationLong2</item>
</style>

<style name="Widget.Material3.TabLayout" parent="Base.Widget.Material3.TabLayout"/>
Expand Down

0 comments on commit d1c5a52

Please sign in to comment.