Skip to content

Commit 655caed

Browse files
afohrmanikim24
authored andcommitted
[Motion] Added theming to MaterialFadeThrough transition.
PiperOrigin-RevId: 351843861
1 parent 478b412 commit 655caed

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,25 @@
1616

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

19+
import com.google.android.material.R;
20+
21+
import androidx.annotation.AttrRes;
22+
1923
/**
2024
* A {@link androidx.transition.Visibility} transition that, by default, provides a fade in and
2125
* scale out when appearing and a fade out and scale out when disappearing.
26+
*
27+
* <p>MaterialFadeThrough supports theme-based easing and duration. The transition will load theme
28+
* values from the {@code SceneRoot}'s context before it runs, and only use them if the
29+
* corresponding properties weren't already set on the transition instance.
2230
*/
2331
public final class MaterialFadeThrough extends MaterialVisibility<FadeThroughProvider> {
2432

2533
private static final float DEFAULT_START_SCALE = 0.92f;
2634

35+
@AttrRes private static final int DEFAULT_THEMED_DURATION_ATTR = R.attr.motionDurationLong1;
36+
@AttrRes private static final int DEFAULT_THEMED_EASING_ATTR = R.attr.motionEasingStandard;
37+
2738
public MaterialFadeThrough() {
2839
super(createPrimaryAnimatorProvider(), createSecondaryAnimatorProvider());
2940
}
@@ -38,4 +49,16 @@ private static VisibilityAnimatorProvider createSecondaryAnimatorProvider() {
3849
scaleProvider.setIncomingStartScale(DEFAULT_START_SCALE);
3950
return scaleProvider;
4051
}
52+
53+
@AttrRes
54+
@Override
55+
int getDurationThemeAttrResId(boolean appearing) {
56+
return DEFAULT_THEMED_DURATION_ATTR;
57+
}
58+
59+
@AttrRes
60+
@Override
61+
int getEasingThemeAttrResId(boolean appearing) {
62+
return DEFAULT_THEMED_EASING_ATTR;
63+
}
4164
}

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

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

23+
import com.google.android.material.R;
24+
25+
import androidx.annotation.AttrRes;
26+
2327
/**
2428
* A {@link android.transition.Visibility} transition that, by default, provides a fade in and
2529
* scale out when appearing and a fade out and scale out when disappearing.
30+
*
31+
* <p>MaterialFadeThrough supports theme-based easing and duration. The transition will load theme
32+
* values from the {@code SceneRoot}'s context before it runs, and only use them if the
33+
* corresponding properties weren't already set on the transition instance.
2634
*/
2735
@androidx.annotation.RequiresApi(android.os.Build.VERSION_CODES.LOLLIPOP)
2836
public final class MaterialFadeThrough extends MaterialVisibility<FadeThroughProvider> {
2937

3038
private static final float DEFAULT_START_SCALE = 0.92f;
3139

40+
@AttrRes private static final int DEFAULT_THEMED_DURATION_ATTR = R.attr.motionDurationLong1;
41+
@AttrRes private static final int DEFAULT_THEMED_EASING_ATTR = R.attr.motionEasingStandard;
42+
3243
public MaterialFadeThrough() {
3344
super(createPrimaryAnimatorProvider(), createSecondaryAnimatorProvider());
3445
}
@@ -43,4 +54,16 @@ private static VisibilityAnimatorProvider createSecondaryAnimatorProvider() {
4354
scaleProvider.setIncomingStartScale(DEFAULT_START_SCALE);
4455
return scaleProvider;
4556
}
57+
58+
@AttrRes
59+
@Override
60+
int getDurationThemeAttrResId(boolean appearing) {
61+
return DEFAULT_THEMED_DURATION_ATTR;
62+
}
63+
64+
@AttrRes
65+
@Override
66+
int getEasingThemeAttrResId(boolean appearing) {
67+
return DEFAULT_THEMED_EASING_ATTR;
68+
}
4669
}

0 commit comments

Comments
 (0)