Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

constraintlayout.widget.Group animation not working with TransitionManager

does anyone has any idea why animating constraintlayout.widget.Group visibility with TransitionManager is not working? Isn't this widget made for these kind of things?

It is working if hiding or showing items after separating views from Group

        <androidx.constraintlayout.widget.Group
            android:id="@+id/cardHeadersGroup"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:visibility="invisible"
            app:constraint_referenced_ids="cardSystemHeader,cardSimpleHeader,cardCombinedHeader"
            app:layout_constraintBottom_toBottomOf="@+id/cardCombinedHeader"
            app:layout_constraintEnd_toEndOf="@+id/cardSystemHeader"
            app:layout_constraintStart_toStartOf="@+id/cardSimpleHeader"
            app:layout_constraintTop_toTopOf="parent"
            tools:visibility="visible"/>
 val headersGroup = binding.cardHeadersGroup

        val slideIn = Slide()
        slideIn.slideEdge = Gravity.BOTTOM
        slideIn.mode = Slide.MODE_IN
        slideIn.addTarget(headersGroup)

        TransitionManager.beginDelayedTransition(binding.root as ViewGroup, slideIn)

        headersGroup.visibility = VISIBLE

like image 273
Antonis Radz Avatar asked Dec 22 '22 22:12

Antonis Radz


1 Answers

I've been recently working with TransitionManager and ConstraintLayout.Group and found it to be very buggy.

Eventually I decided to dump the whole ConstraintLayout.Group and created an in-code AnimationGroup (similar to the in-xml ConstraintLayout.Group):

class AnimationGroup(vararg val views: View) {
    var visibility: Int = View.INVISIBLE
        set(value) {
            views.forEach { it.visibility = value }
            field = value
        }
}

and an extension function for the Transition:

private fun Transition.addTarget(animationGroup: AnimationGroup) {
    animationGroup.views.forEach { viewInGroup -> this.addTarget(viewInGroup) }
}

That way you can do the following (almost exactly the same code, but simpler xml - no ConstraintLayout.Group):

val headersGroup = AnimationGroup(
    binding.cardSystemHeader, 
    binding.cardSimpleHeader, 
    binding.cardCombinedHeader
)

val slideIn = Slide()
slideIn.slideEdge = Gravity.BOTTOM
slideIn.mode = Slide.MODE_IN
slideIn.addTarget(headersGroup)

TransitionManager.beginDelayedTransition(binding.root as ViewGroup, slideIn)

headersGroup.visibility = VISIBLE
like image 113
Bartek Lipinski Avatar answered Dec 25 '22 23:12

Bartek Lipinski