package com.gh.gamecenter.gamedetail.detail

import androidx.recyclerview.widget.RecyclerView
import com.gh.gamecenter.common.utils.LeftPagerSnapHelper

class GameDetailCoverSnapHelper: LeftPagerSnapHelper() {
    override fun findTargetSnapPosition(
        layoutManager: RecyclerView.LayoutManager,
        velocityX: Int,
        velocityY: Int
    ): Int {
        val closestChild = findSnapView(layoutManager) ?: return RecyclerView.NO_POSITION
        val position = layoutManager.getPosition(closestChild)
        return if (position == RecyclerView.NO_POSITION) {
            RecyclerView.NO_POSITION
        } else {
            val forwardDirection = if (layoutManager.canScrollHorizontally()) velocityX > 0 else velocityY > 0
            if (forwardDirection) position + 1 else position - 1
        }
    }
}