Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow child views to intercept touch events #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -518,19 +518,14 @@ class SwipeActionView : FrameLayout {
prepareDrag(e)
}

MotionEvent.ACTION_MOVE -> {
return handleMoveEvent(e)
}

MotionEvent.ACTION_UP,
MotionEvent.ACTION_CANCEL -> {
cancelDrag()
animateToOriginalPosition()
}
}

// In most cases we don't want to handle touch events alone. We give child views a chance to
// intercept them.
// Give child views a chance to intercept touch events before this view.
return false
}

Expand All @@ -539,6 +534,12 @@ class SwipeActionView : FrameLayout {
MotionEvent.ACTION_DOWN -> {
prepareDrag(e)
prepareMessages(e)

// Stop the animator to allow "catching" of view.
// By "catching" I mean the possibility for user to click on the view and continue swiping
// from the position at which it was when starting new swipe.
animator.cancel()

return true
}

Expand Down Expand Up @@ -612,11 +613,6 @@ class SwipeActionView : FrameLayout {
initialRawX = e.rawX
initialRawY = e.rawY

// Stop the animator to allow "catching" of view.
// By "catching" I mean the possibility for user to click on the view and continue swiping
// from the position at which it was when starting new swipe.
animator.cancel()

handler.removeOurMessages()
}

Expand Down
2 changes: 2 additions & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,7 @@
app:cardElevation="10dp" />

</me.thanel.swipeactionview.SwipeActionView>

<include layout="@layout/item_with_horizontal_scroll_view" />
</LinearLayout>
</ScrollView>
44 changes: 44 additions & 0 deletions sample/src/main/res/layout/item_with_horizontal_scroll_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<me.thanel.swipeactionview.SwipeActionView 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"
style="@style/SwipeItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:sav_swipeLeftRippleColor="@color/colorAccent"
app:sav_swipeRightRippleColor="@color/colorPrimary"
tools:ignore="ContentDescription,HardcodedText">

<ImageView style="@style/Icon" />

<ImageView
style="@style/Icon"
android:layout_gravity="end|center_vertical" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical"
android:padding="16dp">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This view contains a horizontally scrolling child view below which will take preference in intercepting swipe events." />

<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="This is a text view located in a horizontally scrolling container. When swiping here SwipeActionView won't activate." />

</HorizontalScrollView>

</LinearLayout>

</me.thanel.swipeactionview.SwipeActionView>