Created
November 20, 2022 18:49
-
-
Save ercnksgl/d427f00eacadcc6e233b1baab89fc8b1 to your computer and use it in GitHub Desktop.
ViewPager inside RecyclerView Scroll issue
This file contains 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