|
51 | 51 | @RequiresApi(VERSION_CODES.LOLLIPOP) |
52 | 52 | public class MaterialContainerTransformSharedElementCallback extends SharedElementCallback { |
53 | 53 |
|
54 | | - private static final int BACKGROUND_FADE_EXTRA_DURATION = 60; |
55 | | - |
56 | 54 | @Nullable private static WeakReference<View> capturedSharedElement; |
57 | 55 |
|
58 | 56 | private boolean entering = true; |
59 | 57 | private boolean transparentWindowBackgroundEnabled = true; |
| 58 | + private boolean sharedElementReenterTransitionEnabled = false; |
60 | 59 | @Nullable private Rect returnEndBounds; |
61 | 60 | @Nullable private ShapeProvider shapeProvider = new ShapeableViewShapeProvider(); |
62 | 61 |
|
@@ -209,10 +208,32 @@ public void setTransparentWindowBackgroundEnabled(boolean transparentWindowBackg |
209 | 208 | this.transparentWindowBackgroundEnabled = transparentWindowBackgroundEnabled; |
210 | 209 | } |
211 | 210 |
|
| 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 | + |
212 | 230 | private void setUpEnterTransform(final Window window) { |
213 | 231 | Transition transition = window.getSharedElementEnterTransition(); |
214 | 232 | if (transition instanceof MaterialContainerTransform) { |
215 | 233 | MaterialContainerTransform transform = (MaterialContainerTransform) transition; |
| 234 | + if (!sharedElementReenterTransitionEnabled) { |
| 235 | + window.setSharedElementReenterTransition(null); |
| 236 | + } |
216 | 237 | if (transparentWindowBackgroundEnabled) { |
217 | 238 | updateBackgroundFadeDuration(window, transform); |
218 | 239 | transform.addListener( |
@@ -296,14 +317,11 @@ private static void restoreWindowBackground(Window window) { |
296 | 317 | } |
297 | 318 |
|
298 | 319 | /** |
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. |
303 | 322 | */ |
304 | 323 | private static void updateBackgroundFadeDuration( |
305 | 324 | Window window, MaterialContainerTransform transform) { |
306 | | - window.setTransitionBackgroundFadeDuration( |
307 | | - transform.getDuration() + BACKGROUND_FADE_EXTRA_DURATION); |
| 325 | + window.setTransitionBackgroundFadeDuration(transform.getDuration()); |
308 | 326 | } |
309 | 327 | } |
0 commit comments