How to trigger MotionLayout swipe animation in particular zone of the screen?

Viewed 140

I am trying to implement BottomSheetFragment (fragment that is staying out of screen and slides in when I need it to), and I am struggling with limit onSwipe trigger.

I want bottom sheet to start appearing only if user swipes from the bottom of the screen, but onSwipe animation is triggered even in the middle of the screen.

My onSwipe:

<OnSwipe
    app:dragDirection="dragUp"
    app:touchAnchorId="@+id/bottom_sheet_fragment"
    app:touchAnchorSide="top" />
1 Answers

You can limit the region that will activate the onSwipe with app:limitBoundsTo="@+id/view"

This will limit the start of the gesture to the bounds of that view even if the view is invisible.

Use the constraints on the view to position it to the region.

e.g.

 <View
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:id="+id/touchArea"
    android:visibility="invisible"
    app:layout_constraintBottom_toBottomOf="parent" />

then add

app:limitBoundsTo="@+id/touchArea"

to your touch area.

Related