material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.42k stars 3.08k forks source link

[motion] Get crash reports when using container anim between two activities #2309

Closed Bradmrhong closed 3 years ago

Bradmrhong commented 3 years ago

Description: Get crash report when using container anim between two activities. StartActivity: A recycler view that contains several cards. EndActivity: A recycler view in which each view holder is full screen.

It's very similar to https://github.com/skydoves/transformationlayout image

Everything worked fine, but I got some crash reports as below:

Expected behavior: Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable.mutate()' on a null object reference at com.google.android.material.transition.platform.MaterialContainerTransformSharedElementCallback.removeWindowBackground(MaterialContainerTransformSharedElementCallback.java:304) at com.google.android.material.transition.platform.MaterialContainerTransformSharedElementCallback.access$000(MaterialContainerTransformSharedElementCallback.java:52) at com.google.android.material.transition.platform.MaterialContainerTransformSharedElementCallback$1.onTransitionStart(MaterialContainerTransformSharedElementCallback.java:243) at android.transition.Transition.start(Transition.java:1897) at android.transition.Transition.runAnimators(Transition.java:868) at android.transition.TransitionSet.runAnimators(TransitionSet.java:433) at android.transition.TransitionSet.runAnimators(TransitionSet.java:433) at android.transition.TransitionSet.runAnimators(TransitionSet.java:433) at android.transition.Transition.playTransition(Transition.java:1778) at android.transition.TransitionManager$MultiListener.onPreDraw(TransitionManager.java:306) at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2223) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1272) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6408) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:874) at android.view.Choreographer.doCallbacks(Choreographer.java:686) at android.view.Choreographer.doFrame(Choreographer.java:621) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6165) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)

Source code: Just refer to the sample code from this repo

Android API version: targetApi: 23

Material Library version: Material Android Library version: 1.3.0

Device: Device on which the bug was encountered here Galaxy J7(6.0.1) Moto G4 Play(7.1.1)

Bradmrhong commented 3 years ago

updates:

I try to work around it by making a copy of MaterialContainerTransformSharedElementCallback and add

if (window.getDecorView().getBackground() == null) {
      window.getDecorView().setBackground(window.getContext().getDrawable(R.color.transparent));
}

The crash is gone.

Also, I try to set transparentWindowBackgroundEnabled = false but getting black background when performing the return transition.

Bradmrhong commented 3 years ago

@drchen Hi it seems window.getDecorView().getBackground() == null sometimes on Android 5,6,7 devices. Will you update the library in the new version?

Thanks!

drchen commented 3 years ago

Yes the fix will be in the next library version, which we don't have a decided date yet but probably in 2 weeks or so.

codedfiles commented 3 years ago

Duplicate of #

Bradmrhong commented 3 years ago

@drchen I found another issue below by using the same demo https://github.com/skydoves/transformationlayout

The card will offset after back to HomeFragment. See below:

https://user-images.githubusercontent.com/29533679/128883658-2fa87845-1cea-4893-b831-c86c601c77e4.mp4

It‘s really strange. please let me know if any ideas?

Thanks!

Bradmrhong commented 3 years ago

@drchen Hi, just wonder know if you have checked this issue? :)