https://kotlinlang.org logo
#compose
Title
# compose
n

Nabeel

06/03/2022, 11:37 AM
When using
MaterialSharedAxis
transition for fragment with
ComposeView
getting crash when pressing back button, Full question in Thread
3
Fragment
Copy code
class TimelineFragment : Fragment() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        
        val axis = MaterialSharedAxis.Z

        val forward = MaterialSharedAxis(axis, true)
        val backward = MaterialSharedAxis(axis, false)

        enterTransition = forward
        exitTransition = forward
        reenterTransition = backward
        returnTransition = backward
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ) = ComposeView(requireActivity()).apply { 
        setContent { 
            Text(text = "Testing")
        }
    }
}
Stacktrace
Copy code
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.farmersbyte.agripro, PID: 8524
java.lang.UnsupportedOperationException: Cannot add views to ComposeView; only Compose content is supported
    at androidx.compose.ui.platform.AbstractComposeView.checkAddView(ComposeView.android.kt:202)
    at androidx.compose.ui.platform.AbstractComposeView.addView(ComposeView.android.kt:346)
    at androidx.transition.TransitionUtils.createViewBitmap(TransitionUtils.java:138)
    at androidx.transition.TransitionUtils.copyViewImage(TransitionUtils.java:64)
    at androidx.transition.Visibility.onDisappear(Visibility.java:404)
    at androidx.transition.Visibility.createAnimator(Visibility.java:257)
    at androidx.transition.Transition.createAnimators(Transition.java:744)
    at androidx.transition.TransitionSet.createAnimators(TransitionSet.java:480)
    at androidx.transition.TransitionSet.createAnimators(TransitionSet.java:480)
    at androidx.transition.Transition.playTransition(Transition.java:1808)
    at androidx.transition.TransitionManager$MultiListener.onPreDraw(TransitionManager.java:300)
    at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1088)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2745)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1721)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7598)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966)
    at android.view.Choreographer.doCallbacks(Choreographer.java:790)
    at android.view.Choreographer.doFrame(Choreographer.java:725)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:951)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7356)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Using jetpack navigation component for fragment navigations. crash is only happening when back press with
MaterialSharedAxis
transition set for fragment. Works fine in compose version
1.0.1
but getting crashes in version
1.1.0
and above.
Related Stackoverflow question
45 Views