Created
April 22, 2019 08:26
-
-
Save tizisdeepan/c8af205cc9a97508157da10e99e5de77 to your computer and use it in GitHub Desktop.
A ViewPager component that disables swipe navigation.
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
import android.content.Context | |
import android.view.MotionEvent | |
import androidx.viewpager.widget.ViewPager | |
import android.util.AttributeSet | |
class LockableViewPager : ViewPager { | |
var swipeLocked: Boolean = true | |
constructor(context: Context) : super(context) | |
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) | |
override fun onTouchEvent(event: MotionEvent): Boolean { | |
return !swipeLocked && super.onTouchEvent(event) | |
} | |
override fun onInterceptTouchEvent(event: MotionEvent): Boolean { | |
return !swipeLocked && super.onInterceptTouchEvent(event) | |
} | |
override fun canScrollHorizontally(direction: Int): Boolean { | |
return !swipeLocked && super.canScrollHorizontally(direction) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment