androidx.compose.material3.carousel

CarouselState

Class

No hand-written docs yet.

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

class CarouselState(
    currentItem: Int = 0,
    currentItemOffsetFraction: Float = 0f,
    itemCount: () -> Int,
) : ScrollableState

Is a

How to get one

Create it

Ready-made values and functions that return it

Used by

Parameters that take a CarouselState.

Properties

currentItemSince 1.9

val currentItem: Int

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.

Saver

val Saver: Saver<CarouselState, *>

To keep current item and item offset saved

Functions

scrollToItemSince 1.9

fun scrollToItem(item: Int)

Scroll (jump immediately) to a given item.

animateScrollToItemSince 1.9

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.

Library docs

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