Created
April 22, 2019 08:33
-
-
Save tizisdeepan/9a9423d54240f9ea68e80f812f4bca29 to your computer and use it in GitHub Desktop.
A ViewPager component that has no animation while switching between pages.
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.util.AttributeSet | |
import android.view.MotionEvent | |
class AnimationlessViewpager : androidx.viewpager.widget.ViewPager { | |
var swipeLocked: Boolean = true | |
constructor(context: Context) : super(context) | |
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) | |
override fun onTouchEvent(event: MotionEvent): Boolean = !swipeLocked && super.onTouchEvent(event) | |
override fun onInterceptTouchEvent(event: MotionEvent): Boolean = !swipeLocked && super.onInterceptTouchEvent(event) | |
override fun canScrollHorizontally(direction: Int): Boolean = !swipeLocked && super.canScrollHorizontally(direction) | |
override fun setCurrentItem(item: Int) { | |
super.setCurrentItem(item, false) | |
} | |
override fun setCurrentItem(item: Int, smoothScroll: Boolean) { | |
super.setCurrentItem(item, false) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment