Reputation: 149
I am testing multistate transitions just like in the below sample.
My layout is pretty straightfoward. It has a header with a recyclerview below it. So for testing purposes I am trying to perform the following transitions.
Transition 1 Header changes its size from 500dp(start state) to 200dp(intermediate state)
Transition 2 Header changes its size from 200dp(intermediate state) to 0dp(end state)
The problem is only first transition happens. My desired behavior is when I scroll the list T1 occurs and right after it T2 should occur making the header collapse completely.
Please NOTE- I am doing this for testing only. I have an animation that I need to develop that uses the same principle here
Here's the code
Layout
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/motion_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:showPaths="true"
app:layoutDescription="@xml/scrollable_header_above_recycler_view_scene">
<ImageView
android:id="@+id/header"
android:layout_width="0dp"
android:layout_height="500dp"
android:background="@color/colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:paddingTopSystemWindowInsets="@{true}"
tools:ignore="ContentDescription" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="0dp"
android:layout_height="0dp"
android:clipToPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/header"
app:paddingBottomSystemWindowInsets="@{true}" />
</androidx.constraintlayout.motion.widget.MotionLayout>
</layout>
MotionLayout
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
motion:constraintSetStart="@+id/start"
motion:constraintSetEnd="@+id/intermediate"
>
<OnSwipe
motion:onTouchUp="stop"
motion:dragDirection="dragUp"
motion:touchAnchorSide="bottom"
motion:touchAnchorId="@+id/header" />
</Transition>
<Transition
motion:constraintSetStart="@+id/intermediate"
motion:constraintSetEnd="@+id/end"
>
<OnSwipe
motion:onTouchUp="stop"
motion:dragDirection="dragDown"
motion:touchAnchorSide="bottom"
motion:touchAnchorId="@+id/header" />
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="500dp"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>
<ConstraintSet android:id="@+id/intermediate">
<Constraint
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="200dp"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
/>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="0dp"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
/>
</ConstraintSet>
</MotionScene>
Upvotes: 2
Views: 1482
Reputation: 61
Looks like a bug. I've reported it to google issue tracker....you can set the transitions and the progress manually with a listener to prevent it for now, something like:
// MotionLayout
motionLayout.setTransitionListener(object : MotionLayout.TransitionListener {
override fun onTransitionTrigger(p0: MotionLayout?, p1: Int, p2: Boolean, p3: Float) {}
override fun onTransitionStarted(p0: MotionLayout?, p1: Int, p2: Int) {}
override fun onTransitionChange(p0: MotionLayout?, p1: Int, p2: Int, p3: Float) {}
override fun onTransitionCompleted(p0: MotionLayout?, p1: Int) {
if (motionLayout.currentState == R.id.set1 && motionLayout.endState == R.id.set1) {
motionLayout.progress = 0F
motionLayout.setTransition(R.id.set1, R.id.set2)
} else if (motionLayout.currentState == R.id.set1 && motionLayout.endState == R.id.set2) {
motionLayout.progress = 1F
motionLayout.setTransition(R.id.set0, R.id.set1)
}
}
})
Upvotes: 2
Reputation: 5323
MotionLayout does not support Multi-state transitions of NestedScrollView/RecyclerView. It would generate way to many corner cases.
Upvotes: 0