package com.cheng.blzb.widget

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.viewpager.widget.ViewPager

class NoScrollViewPager @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ViewPager(context, attrs) {
    private var scrollable: Boolean = false

    fun setScrollable(scrollable: Boolean) {
        this.scrollable = scrollable
    }

    override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
        if (!scrollable) return false
        return super.onInterceptTouchEvent(ev)
    }

    @SuppressLint("ClickableViewAccessibility")
    override fun onTouchEvent(ev: MotionEvent?): Boolean {
        if (!scrollable) return false
        return super.onTouchEvent(ev)
    }
}