Skip to content

Commit e72c001

Browse files
committed
[Motion] Removed extra transition background fade duration from MaterialContainerTransformSharedElementCallback in favor of nulling out sharedElementReenterTransition to prevent extra transition from happening
Related to #1433 Related to #1344 PiperOrigin-RevId: 322614608
1 parent baddfdb commit e72c001

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

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

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@
5151
@RequiresApi(VERSION_CODES.LOLLIPOP)
5252
public class MaterialContainerTransformSharedElementCallback extends SharedElementCallback {
5353

54-
private static final int BACKGROUND_FADE_EXTRA_DURATION = 60;
55-
5654
@Nullable private static WeakReference<View> capturedSharedElement;
5755

5856
private boolean entering = true;
5957
private boolean transparentWindowBackgroundEnabled = true;
58+
private boolean sharedElementReenterTransitionEnabled = false;
6059
@Nullable private Rect returnEndBounds;
6160
@Nullable private ShapeProvider shapeProvider = new ShapeableViewShapeProvider();
6261

@@ -209,10 +208,32 @@ public void setTransparentWindowBackgroundEnabled(boolean transparentWindowBackg
209208
this.transparentWindowBackgroundEnabled = transparentWindowBackgroundEnabled;
210209
}
211210

211+
/**
212+
* Returns whether incoming Activity's sharedElementReenterTransition will be respected.
213+
*
214+
* @see #setSharedElementReenterTransitionEnabled(boolean)
215+
*/
216+
public boolean isSharedElementReenterTransitionEnabled() {
217+
return sharedElementReenterTransitionEnabled;
218+
}
219+
220+
/**
221+
* If enabled, the Activity's sharedElementReenterTransition will be respected; otherwise it will
222+
* be set to null. Default is false, meaning the sharedElementReenterTransition will be set to
223+
* null.
224+
*/
225+
public void setSharedElementReenterTransitionEnabled(
226+
boolean sharedElementReenterTransitionEnabled) {
227+
this.sharedElementReenterTransitionEnabled = sharedElementReenterTransitionEnabled;
228+
}
229+
212230
private void setUpEnterTransform(final Window window) {
213231
Transition transition = window.getSharedElementEnterTransition();
214232
if (transition instanceof MaterialContainerTransform) {
215233
MaterialContainerTransform transform = (MaterialContainerTransform) transition;
234+
if (!sharedElementReenterTransitionEnabled) {
235+
window.setSharedElementReenterTransition(null);
236+
}
216237
if (transparentWindowBackgroundEnabled) {
217238
updateBackgroundFadeDuration(window, transform);
218239
transform.addListener(
@@ -296,14 +317,11 @@ private static void restoreWindowBackground(Window window) {
296317
}
297318

298319
/**
299-
* When using a transparent window background, make sure that the background fade duration is at
300-
* least as long as the transform's duration. This will help to avoid a black background visual
301-
* artifact and an extra transition from happening after the container transform on certain API
302-
* levels.
320+
* When using a transparent window background, make sure that the background fade duration is as
321+
* long as the transform's duration. This will help to avoid a black background visual artifact.
303322
*/
304323
private static void updateBackgroundFadeDuration(
305324
Window window, MaterialContainerTransform transform) {
306-
window.setTransitionBackgroundFadeDuration(
307-
transform.getDuration() + BACKGROUND_FADE_EXTRA_DURATION);
325+
window.setTransitionBackgroundFadeDuration(transform.getDuration());
308326
}
309327
}

0 commit comments

Comments
 (0)