material-components-android: [MaterialContainerTransform] IllegalStateException: "End view bounds must not be null, make sure the end view is laid out and measured"
I am not sure if this should be a question or a bug report, but after updating to material 1.2.0-beta01 I am starting to see random crashes in production when using MaterialContainerTransform as a sharedelementreturntransition. Same issue is there in the 1.3.0 alpha1.
I cannot reproduce this on any of my devices, but in production there is a 5% crash rate.
StackTrace:
Fatal Exception: java.lang.IllegalStateException: End view bounds must not be null, make sure the end view is laid out and measured
at com.google.android.material.transition.MaterialContainerTransform.createAnimator(MaterialContainerTransform.java:889)
at androidx.transition.Transition.createAnimators(Transition.java:747)
at androidx.transition.TransitionSet.createAnimators(TransitionSet.java:480)
at androidx.transition.TransitionSet.createAnimators(TransitionSet.java:480)
at androidx.transition.Transition.playTransition(Transition.java:1821)
at androidx.transition.TransitionManager$MultiListener.onPreDraw(TransitionManager.java:301)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1102)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3310)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2200)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9065)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:999)
at android.view.Choreographer.doCallbacks(Choreographer.java:797)
at android.view.Choreographer.doFrame(Choreographer.java:732)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:984)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8016)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
How can I make sure that the end view is laid out and measured?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 17 (5 by maintainers)
Thanks for looking into this!
Ok I’ve looked into this a bit more considering the androidx/framework
ChangeBoundstransition, which is comparable toMaterialContainerTransform. Whether intentionally or not, it seems likeChangeBoundswill short-circuit before accessing null bounds objects, because of this view parent check and the fact that the parent property is only set when non-null bounds are set.So I think it makes sense to be consistent with that behavior, even if it means some developers won’t find out about this potential misconfiguration. Assuming we don’t find any other reasoning, I will change our IllegalStateException to be an early return with a log warning.
Can you easily reproduce the scenario locally? Maybe you can try adding an
OnLayoutChangeListenerorOnGlobalLayoutListenerto the root view of your second fragment, and then useMaterialContainerTransform#setEndViewto change the “target” view?However, it would have to be done before the Transitions framework calls
captureEndValueson ourMaterialContainerTransform.If changing the end view doesn’t work then maybe you can try calling
MaterialContainerTransform#cancelif you detect the scenario in the layout listener.