Forked from ercnksgl/DisallowParentSwipeOnItemTouchListener.kt
Created
November 22, 2022 03:32
-
-
Save virendersran01/31e897b5843548d8284a0af339621bb6 to your computer and use it in GitHub Desktop.
ViewPager inside RecyclerView Scroll issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ercnksgl.testapp.util | |
import android.view.MotionEvent | |
import androidx.recyclerview.widget.RecyclerView | |
import kotlin.math.abs | |
class DisallowParentSwipeOnItemTouchListener : RecyclerView.OnItemTouchListener { | |
var startPoint = 0f | |
override fun onInterceptTouchEvent( | |
rv: RecyclerView, | |
e: MotionEvent | |
): Boolean { | |
when (e.action) { | |
MotionEvent.ACTION_DOWN -> { | |
startPoint = e.x | |
} | |
MotionEvent.ACTION_MOVE -> { | |
val pointX = e.x | |
if (abs(pointX - startPoint) > 5f) { | |
//scrolling horizontally | |
rv.parent.requestDisallowInterceptTouchEvent(true) | |
} | |
} | |
MotionEvent.ACTION_UP, | |
MotionEvent.ACTION_CANCEL -> { | |
rv.parent.requestDisallowInterceptTouchEvent(false) | |
} | |
} | |
return false | |
} | |
override fun onTouchEvent(rv: RecyclerView, e: MotionEvent) {} | |
override fun onRequestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment