google-developer-training/advanced-android-kotlin-motionlayout

Updating subviews visibility and state in MotionLayout

Opened this issue · 3 comments

Android apps consists of many viewgroup/view layers and MotionLayouts will often be in the top layer and surely cant contain all the updates of all its subviews states within the MotionLayout animation. It is therefore important that updates can be applied to subviews states after the initial MotionLayout animation.

Updating visibility of subviews programmatically (eg. subview.visibility = View.GONE) often doesnt work even if trying to force the view to update (invalidate() or requestLayout()).

Please fix this issue.

Experienced using:
androidx.constraintlayout:constraintlayout:2.2.0-alpha05

Generally the only thing you can do is set layoutDuringTransition="hornorRequest" in the Transition
See:
androidx/constraintlayout#405

The core of the problem is many views generate unnecessary request layout which get expensive and can make
MotionLayout un usable.

This also when after the transition has ended. So your fix doesn't work @jafu888