CarouselState

class CarouselState(currentItem: Int = 0, @FloatRange(from = -0.5, to = 0.5) currentItemOffsetFraction: Float = 0.0f, itemCount: () -> Int) : ScrollableState

The state that can be used to control all types of carousels.

Parameters

currentItem

the current item to be scrolled to.

currentItemOffsetFraction

the offset of the current item as a fraction of the item's size. This should vary between -0.5 and 0.5 and indicates how to offset the current item from the snapped position.

itemCount

the number of items this Carousel will have.

Constructors

Link copied to clipboard
constructor(currentItem: Int = 0, @FloatRange(from = -0.5, to = 0.5) currentItemOffsetFraction: Float = 0.0f, itemCount: () -> Int)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The item that sits closest to the snapped position. This is an observable value and will change as the carousel scrolls either by gesture or animation.

Link copied to clipboard
open override val isScrollInProgress: Boolean
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
suspend fun animateScrollToItem(item: Int, animationSpec: AnimationSpec<Float> = spring())

Scroll animate to a given item. If the item is too far away from currentItem, Carousel will avoid composing all intermediate items by jumping to a nearer item before animating the scroll.

Link copied to clipboard
open override fun dispatchRawDelta(delta: Float): Float
Link copied to clipboard
open suspend override fun scroll(scrollPriority: MutatePriority, block: suspend ScrollScope.() -> Unit)
Link copied to clipboard
suspend fun scrollToItem(item: Int)

Scroll (jump immediately) to a given item.