Skip to content

Commit

Permalink
Disable fling gesture for message list swipe actions
Browse files Browse the repository at this point in the history
  • Loading branch information
hafizhasyimm authored and cketti committed Oct 25, 2023
1 parent ab7d680 commit 7af17d2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class MessageListSwipeCallback(
swipeLeftLayout = layoutInflater.inflate(R.layout.swipe_left_action, null, false)
}

override fun isFlingEnabled(): Boolean {
return false
}

override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: ViewHolder): Int {
if (viewHolder !is MessageViewHolder) return 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ private int swipeIfNecessary(ViewHolder viewHolder) {
private int checkHorizontalSwipe(ViewHolder viewHolder, int flags) {
if ((flags & (LEFT | RIGHT)) != 0) {
final int dirFlag = mDx > 0 ? RIGHT : LEFT;
if (mVelocityTracker != null && mActivePointerId > -1) {
if (mCallback.isFlingEnabled() && mVelocityTracker != null && mActivePointerId > -1) {
mVelocityTracker.computeCurrentVelocity(PIXELS_PER_SECOND,
mCallback.getSwipeVelocityThreshold(mMaxSwipeVelocity));
final float xVelocity = mVelocityTracker.getXVelocity(mActivePointerId);
Expand All @@ -1326,7 +1326,7 @@ private int checkHorizontalSwipe(ViewHolder viewHolder, int flags) {
private int checkVerticalSwipe(ViewHolder viewHolder, int flags) {
if ((flags & (UP | DOWN)) != 0) {
final int dirFlag = mDy > 0 ? DOWN : UP;
if (mVelocityTracker != null && mActivePointerId > -1) {
if (mCallback.isFlingEnabled() && mVelocityTracker != null && mActivePointerId > -1) {
mVelocityTracker.computeCurrentVelocity(PIXELS_PER_SECOND,
mCallback.getSwipeVelocityThreshold(mMaxSwipeVelocity));
final float xVelocity = mVelocityTracker.getXVelocity(mActivePointerId);
Expand Down Expand Up @@ -2280,6 +2280,11 @@ public void onSwipeDirectionChanged(@NonNull ViewHolder viewHolder, int directio

public void onSwipeEnded(@NonNull ViewHolder viewHolder) {
}

public boolean isFlingEnabled() {
return true;
}

}

/**
Expand Down

0 comments on commit 7af17d2

Please sign in to comment.