animation-samples icon indicating copy to clipboard operation
animation-samples copied to clipboard

Motion: Navigation --> Shared Element will not work for API < 18

Open eneim opened this issue 5 years ago • 1 comments

I import the "Motion" sample as it and My tried with "Navigation --> Shared Element" will crash on emulator v16 with the following trace:

java.lang.UnsupportedOperationException: FragmentContainerView does not support Layout Transitions or animateLayoutChanges="true".
        at androidx.fragment.app.FragmentContainerView.setLayoutTransition(FragmentContainerView.java:104)
        at androidx.transition.ViewGroupUtilsApi14.suppressLayout(ViewGroupUtilsApi14.java:70)
        at androidx.transition.ViewGroupUtils.suppressLayout(ViewGroupUtils.java:62)

It turns out that ViewGroupUtils.suppressLayout will call viewGroup.setLayoutTransition for device with SDK < 18:

    static void suppressLayout(@NonNull ViewGroup group, boolean suppress) {
        if (Build.VERSION.SDK_INT >= 29) {
            group.suppressLayout(suppress);
        } else if (Build.VERSION.SDK_INT >= 18) {
            hiddenSuppressLayout(group, suppress);
        } else {
            // This will call viewGroup.setLayoutTransition(LayoutTransition) and crash.
            ViewGroupUtilsApi14.suppressLayout(group, suppress);
        }
    }

, and the receiver in this case is the FragmentContainerView which prohibits this call.

I'm not seeking for a fix as both are current specification, but I wonder if changing the implementation can be trivial to be done?

eneim avatar Aug 30 '19 13:08 eneim

Thank you for the report. I filed a bug to androidx.fragment. http://issuetracker.google.com/140361893

yaraki avatar Sep 02 '19 07:09 yaraki