Skip to content

Commit 478b412

Browse files
afohrmanikim24
authored andcommitted
[Motion] Added theming to MaterialSharedAxis transition.
PiperOrigin-RevId: 351841194
1 parent 13cd0fe commit 478b412

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

lib/java/com/google/android/material/transition/MaterialSharedAxis.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616

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

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

2123
import android.view.Gravity;
24+
import androidx.annotation.AttrRes;
2225
import androidx.annotation.IntDef;
2326
import androidx.annotation.RestrictTo;
2427
import java.lang.annotation.Retention;
@@ -40,6 +43,10 @@
4043
* true, the target will slide to the left on the X axis, up on the Y axis and out in on the Z axis.
4144
* When false, the target will slide to the right on the X axis, down on the Y axis and in on the Z
4245
* axis. Note that this is independent of whether or not the target is appearing or disappearing.
46+
*
47+
* <p>MaterialSharedAxis supports theme-based easing and duration. The transition will load theme
48+
* values from the {@code SceneRoot}'s context before it runs, and only use them if the
49+
* corresponding properties weren't already set on the transition instance.
4350
*/
4451
public final class MaterialSharedAxis extends MaterialVisibility<VisibilityAnimatorProvider> {
4552

@@ -76,6 +83,9 @@ public final class MaterialSharedAxis extends MaterialVisibility<VisibilityAnima
7683
@Axis private final int axis;
7784
private final boolean forward;
7885

86+
@AttrRes private static final int DEFAULT_THEMED_DURATION_ATTR = R.attr.motionDurationLong1;
87+
@AttrRes private static final int DEFAULT_THEMED_EASING_ATTR = R.attr.motionEasingStandard;
88+
7989
public MaterialSharedAxis(@Axis int axis, boolean forward) {
8090
super(createPrimaryAnimatorProvider(axis, forward), createSecondaryAnimatorProvider());
8191
this.axis = axis;
@@ -108,4 +118,16 @@ private static VisibilityAnimatorProvider createPrimaryAnimatorProvider(
108118
private static VisibilityAnimatorProvider createSecondaryAnimatorProvider() {
109119
return new FadeThroughProvider();
110120
}
121+
122+
@AttrRes
123+
@Override
124+
int getDurationThemeAttrResId(boolean appearing) {
125+
return DEFAULT_THEMED_DURATION_ATTR;
126+
}
127+
128+
@AttrRes
129+
@Override
130+
int getEasingThemeAttrResId(boolean appearing) {
131+
return DEFAULT_THEMED_EASING_ATTR;
132+
}
111133
}

lib/java/com/google/android/material/transition/platform/MaterialSharedAxis.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@
2020
*/
2121
package com.google.android.material.transition.platform;
2222

23+
import com.google.android.material.R;
24+
2325
import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
2426

2527
import android.view.Gravity;
28+
import androidx.annotation.AttrRes;
2629
import androidx.annotation.IntDef;
2730
import androidx.annotation.RestrictTo;
2831
import java.lang.annotation.Retention;
@@ -44,6 +47,10 @@
4447
* true, the target will slide to the left on the X axis, up on the Y axis and out in on the Z axis.
4548
* When false, the target will slide to the right on the X axis, down on the Y axis and in on the Z
4649
* axis. Note that this is independent of whether or not the target is appearing or disappearing.
50+
*
51+
* <p>MaterialSharedAxis supports theme-based easing and duration. The transition will load theme
52+
* values from the {@code SceneRoot}'s context before it runs, and only use them if the
53+
* corresponding properties weren't already set on the transition instance.
4754
*/
4855
@androidx.annotation.RequiresApi(android.os.Build.VERSION_CODES.LOLLIPOP)
4956
public final class MaterialSharedAxis extends MaterialVisibility<VisibilityAnimatorProvider> {
@@ -81,6 +88,9 @@ public final class MaterialSharedAxis extends MaterialVisibility<VisibilityAnima
8188
@Axis private final int axis;
8289
private final boolean forward;
8390

91+
@AttrRes private static final int DEFAULT_THEMED_DURATION_ATTR = R.attr.motionDurationLong1;
92+
@AttrRes private static final int DEFAULT_THEMED_EASING_ATTR = R.attr.motionEasingStandard;
93+
8494
public MaterialSharedAxis(@Axis int axis, boolean forward) {
8595
super(createPrimaryAnimatorProvider(axis, forward), createSecondaryAnimatorProvider());
8696
this.axis = axis;
@@ -113,4 +123,16 @@ private static VisibilityAnimatorProvider createPrimaryAnimatorProvider(
113123
private static VisibilityAnimatorProvider createSecondaryAnimatorProvider() {
114124
return new FadeThroughProvider();
115125
}
126+
127+
@AttrRes
128+
@Override
129+
int getDurationThemeAttrResId(boolean appearing) {
130+
return DEFAULT_THEMED_DURATION_ATTR;
131+
}
132+
133+
@AttrRes
134+
@Override
135+
int getEasingThemeAttrResId(boolean appearing) {
136+
return DEFAULT_THEMED_EASING_ATTR;
137+
}
116138
}

0 commit comments

Comments
 (0)