So we're trying to mimic the behaviour of a peek-able BottomSheetLayout
(a bottom View peeking out from the bottom of the screen, which comes into full-screen view when scrolling it upwards, sort of like this: https://www.youtube.com/watch?v=yrZVLL-z6P4) using MotionLayout
, version 2.0.0-alpha4
.
The problem is that the OnSwipe
transition on the peek-able view doesn't apply to the View itself, it apparently applies to the entire view underneath, in this case a RecyclerView
. So when we scroll the RecyclerView
, the transition is being run.
root_view.xml
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.motion.widget.MotionLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/motion_scene">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:clipToPadding="false"
android:paddingBottom="@dimen/margin_48"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="@dimen/size_48"
android:elevation="@dimen/elevation_12"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="@dimen/elevation_12"
android:rotation="90"
app:layout_constraintBottom_toBottomOf="@id/btn"
app:layout_constraintEnd_toEndOf="@id/btn"
app:layout_constraintTop_toTopOf="@id/btn" />
<FrameLayout
android:id="@+id/fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="@dimen/elevation_8"
app:layout_constraintTop_toBottomOf="parent" />
</androidx.constraintlayout.motion.widget.MotionLayout>
</FrameLayout>
motion_scene.xml
<Transition
android:id="@+id/swipe"
app:constraintSetEnd="@id/end"
app:constraintSetStart="@id/start"
app:duration="250">
<OnSwipe
app:dragDirection="dragUp"
app:touchAnchorId="@id/btn" />
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@id/fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="parent" />
<Constraint
android:id="@id/btn"
android:layout_width="match_parent"
android:layout_height="@dimen/size_48"
app:layout_constraintBottom_toBottomOf="parent" />
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@id/fragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/btn" />
<Constraint
android:id="@id/btn"
android:layout_width="match_parent"
android:layout_height="@dimen/size_48"
app:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>
using both app:touchAnchorId
and app:touchRegionId
together helped me.
<OnSwipe
app:dragDirection="dragUp"
app:touchAnchorId="@id/btn"
app:touchRegionId="@id/btn"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With