Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.content.Context
- import android.util.AttributeSet
- import android.view.View
- import androidx.coordinatorlayout.widget.CoordinatorLayout
- import androidx.core.view.NestedScrollingChild3
- import androidx.core.view.NestedScrollingChildHelper
- class NestedCoordinatorLayout @JvmOverloads constructor(
- context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
- ) : CoordinatorLayout(context, attrs, defStyleAttr), NestedScrollingChild3 {
- private val nestedScrollingChildHelper: NestedScrollingChildHelper = NestedScrollingChildHelper(this)
- init {
- isNestedScrollingEnabled = true
- }
- override fun onStartNestedScroll(child: View, target: View, axes: Int, type: Int): Boolean =
- super.onStartNestedScroll(child, target, axes, type).or(startNestedScroll(axes, type))
- override fun onNestedFling(target: View, velocityX: Float, velocityY: Float, consumed: Boolean): Boolean =
- super.onNestedFling(target, velocityX, velocityY, consumed).or(
- dispatchNestedFling(
- velocityX,
- velocityY,
- consumed
- )
- )
- override fun onNestedPreScroll(target: View, dx: Int, dy: Int, consumed: IntArray, type: Int) {
- super.onNestedPreScroll(target, dx, dy, consumed, type)
- if (consumed[1] == 0) {
- dispatchNestedPreScroll(dx, dy, consumed, null, type)
- }
- }
- override fun onNestedScroll(
- target: View,
- dxConsumed: Int,
- dyConsumed: Int,
- dxUnconsumed: Int,
- dyUnconsumed: Int,
- type: Int,
- consumed: IntArray
- ) {
- super.onNestedScroll(target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type, consumed)
- if (consumed[1] == 0) {
- dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, null, type, consumed)
- }
- }
- override fun onNestedPreFling(target: View, velocityX: Float, velocityY: Float): Boolean =
- super.onNestedPreFling(target, velocityX, velocityY).or(dispatchNestedPreFling(velocityX, velocityY))
- override fun onStopNestedScroll(target: View, type: Int) {
- super.onStopNestedScroll(target, type)
- stopNestedScroll(type)
- }
- override fun dispatchNestedScroll(
- dxConsumed: Int,
- dyConsumed: Int,
- dxUnconsumed: Int,
- dyUnconsumed: Int,
- offsetInWindow: IntArray?,
- type: Int
- ): Boolean = nestedScrollingChildHelper.dispatchNestedScroll(
- dxConsumed,
- dyConsumed,
- dxUnconsumed,
- dyUnconsumed,
- offsetInWindow,
- type
- )
- override fun dispatchNestedScroll(
- dxConsumed: Int,
- dyConsumed: Int,
- dxUnconsumed: Int,
- dyUnconsumed: Int,
- offsetInWindow: IntArray?
- ): Boolean = nestedScrollingChildHelper.dispatchNestedScroll(
- dxConsumed,
- dyConsumed,
- dxUnconsumed,
- dyUnconsumed,
- offsetInWindow
- )
- override fun dispatchNestedScroll(
- dxConsumed: Int,
- dyConsumed: Int,
- dxUnconsumed: Int,
- dyUnconsumed: Int,
- offsetInWindow: IntArray?,
- type: Int,
- consumed: IntArray
- ) {
- nestedScrollingChildHelper.dispatchNestedScroll(
- dxConsumed,
- dyConsumed,
- dxUnconsumed,
- dyUnconsumed,
- offsetInWindow,
- type,
- consumed
- )
- }
- override fun isNestedScrollingEnabled(): Boolean = nestedScrollingChildHelper.isNestedScrollingEnabled
- override fun dispatchNestedPreScroll(
- dx: Int,
- dy: Int,
- consumed: IntArray?,
- offsetInWindow: IntArray?,
- type: Int
- ): Boolean = nestedScrollingChildHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow, type)
- override fun dispatchNestedPreScroll(dx: Int, dy: Int, consumed: IntArray?, offsetInWindow: IntArray?): Boolean =
- nestedScrollingChildHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow)
- override fun stopNestedScroll(type: Int) {
- nestedScrollingChildHelper.stopNestedScroll(type)
- }
- override fun stopNestedScroll() {
- nestedScrollingChildHelper.stopNestedScroll()
- }
- override fun hasNestedScrollingParent(type: Int): Boolean =
- nestedScrollingChildHelper.hasNestedScrollingParent(type)
- override fun hasNestedScrollingParent(): Boolean = nestedScrollingChildHelper.hasNestedScrollingParent()
- override fun dispatchNestedPreFling(velocityX: Float, velocityY: Float): Boolean =
- nestedScrollingChildHelper.dispatchNestedPreFling(velocityX, velocityY)
- override fun setNestedScrollingEnabled(enabled: Boolean) {
- nestedScrollingChildHelper.isNestedScrollingEnabled = enabled
- }
- override fun dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean): Boolean =
- nestedScrollingChildHelper.dispatchNestedFling(velocityX, velocityY, consumed)
- override fun startNestedScroll(axes: Int, type: Int): Boolean =
- nestedScrollingChildHelper.startNestedScroll(axes, type)
- override fun startNestedScroll(axes: Int): Boolean = nestedScrollingChildHelper.startNestedScroll(axes)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement