diff --git a/app/src/main/java/me/saket/dank/widgets/swipe/SwipeableLayout.java b/app/src/main/java/me/saket/dank/widgets/swipe/SwipeableLayout.java index db1853fe0..e5b8cb857 100644 --- a/app/src/main/java/me/saket/dank/widgets/swipe/SwipeableLayout.java +++ b/app/src/main/java/me/saket/dank/widgets/swipe/SwipeableLayout.java @@ -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; @@ -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!"); @@ -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 {