CarouselSnapHelper

public class CarouselSnapHelper
extends SnapHelper

java.lang.Object
   ↳ androidx.recyclerview.widget.RecyclerView.OnFlingListener
     ↳ androidx.recyclerview.widget.SnapHelper
       ↳ com.google.android.material.carousel.CarouselSnapHelper


Implementation of the SnapHelper that supports snapping items to the carousel keylines according to the strategy.

Summary

Public constructors

CarouselSnapHelper()
CarouselSnapHelper(boolean disableFling)

Public methods

void attachToRecyclerView(RecyclerView recyclerView)
int[] calculateDistanceToFinalSnap(RecyclerView.LayoutManager layoutManager, View view)
View findSnapView(RecyclerView.LayoutManager layoutManager)
int findTargetSnapPosition(RecyclerView.LayoutManager layoutManager, int velocityX, int velocityY)

Protected methods

RecyclerView.SmoothScroller createScroller(RecyclerView.LayoutManager layoutManager)

This is mostly a copy of SnapHelper#createSnapScroller with a slight adjustment to call ERROR(/CarouselSnapHelper#calculateDistanceToSnap(LayoutManager, View, boolean)) (LayoutManager, View)}.

Inherited methods

Public constructors

CarouselSnapHelper

public CarouselSnapHelper ()

CarouselSnapHelper

public CarouselSnapHelper (boolean disableFling)

Parameters
disableFling boolean

Public methods

attachToRecyclerView

public void attachToRecyclerView (RecyclerView recyclerView)

Parameters
recyclerView RecyclerView

calculateDistanceToFinalSnap

public int[] calculateDistanceToFinalSnap (RecyclerView.LayoutManager layoutManager, 
                View view)

Parameters
layoutManager RecyclerView.LayoutManager

view View

Returns
int[]

findSnapView

public View findSnapView (RecyclerView.LayoutManager layoutManager)

Parameters
layoutManager RecyclerView.LayoutManager

Returns
View

findTargetSnapPosition

public int findTargetSnapPosition (RecyclerView.LayoutManager layoutManager, 
                int velocityX, 
                int velocityY)

Parameters
layoutManager RecyclerView.LayoutManager

velocityX int

velocityY int

Returns
int

Protected methods

createScroller

protected RecyclerView.SmoothScroller createScroller (RecyclerView.LayoutManager layoutManager)

This is mostly a copy of SnapHelper#createSnapScroller with a slight adjustment to call ERROR(/CarouselSnapHelper#calculateDistanceToSnap(LayoutManager, View, boolean)) (LayoutManager, View)}. We want to do a partial snap since the correct target keyline state may not have updated yet since this gets called before the keylines shift.

Parameters
layoutManager RecyclerView.LayoutManager

Returns
RecyclerView.SmoothScroller