Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Swipe gesture icon position #121

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.FrameLayout;

import timber.log.Timber;

Expand Down Expand Up @@ -134,6 +135,16 @@ protected void dispatchDraw(Canvas canvas) {

// ======== SWIPE ======== //

int valueY = 0;

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_MOVE){
valueY = (int)event.getY();
}
return false;
}

public void setSwipeTranslation(float translationX) {
if (!isLaidOut()) {
Timber.w("SwipeableLayout hasn't been measured yet!");
Expand Down Expand Up @@ -162,6 +173,12 @@ public void setSwipeTranslation(float translationX) {
swipeActionTriggerDrawable.setBounds((int) translationX, 0, (int) (getWidth() + translationX), getHeight());

// Move the icon along with the View being swiped.
if (valueY > (actionIconView.getHeight() / 2)) {
actionIconView.setY(valueY - (actionIconView.getHeight() / 2));
} else {
actionIconView.setY(valueY);
}

if (swipingFromEndToStart) {
actionIconView.setTranslationX(swipeableChild.getRight() + translationX);
} else {
Expand Down