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

Summary

Public companion properties

Saver<CarouselState, *>

To keep current item and item offset saved

Cmn

Public constructors

CarouselState(
    currentItem: Int,
    currentItemOffsetFraction: @FloatRange(from = -0.5, to = 0.5) Float,
    itemCount: () -> Int
)
Cmn

Public functions

open Float

Dispatch scroll delta in pixels avoiding all scroll related mechanisms.

Cmn
open suspend Unit
scroll(scrollPriority: MutatePriority, block: suspend ScrollScope.() -> Unit)

Call this function to take control of scrolling and gain the ability to send scroll events via ScrollScope.scrollBy.

Cmn

Public properties

open Boolean

Whether this ScrollableState is currently scrolling by gesture, fling or programmatically or not.

Cmn
MutableState<() -> Int>
Cmn

Inherited properties

From androidx.compose.foundation.gestures.ScrollableState
open Boolean

Whether this ScrollableState can scroll backward (consume a negative delta).

Cmn
open Boolean

Whether this ScrollableState can scroll forward (consume a positive delta).

Cmn
open Boolean

The value of this property is true under the following scenarios, otherwise it's false.

Cmn
open Boolean

The value of this property is true under the following scenarios, otherwise it's false.

Cmn

Public companion properties

Saver

val SaverSaver<CarouselState, *>

To keep current item and item offset saved

Public constructors

CarouselState

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

the current item to be scrolled to.

currentItemOffsetFraction: @FloatRange(from = -0.5, to = 0.5) Float = 0.0f

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: () -> Int

the number of items this Carousel will have.

Public functions

dispatchRawDelta

open fun dispatchRawDelta(delta: Float): Float

Dispatch scroll delta in pixels avoiding all scroll related mechanisms.

NOTE: unlike scroll, dispatching any delta with this method won't trigger nested scroll, won't stop ongoing scroll/drag animation and will bypass scrolling of any priority. This method will also ignore reverseDirection and other parameters set in scrollable.

This method is used internally for nested scrolling dispatch and other low level operations, allowing implementers of ScrollableState influence the consumption as suits them. Manually dispatching delta via this method will likely result in a bad user experience, you must prefer scroll method over this one.

Parameters
delta: Float

amount of scroll dispatched in the nested scroll process

Returns
Float

the amount of delta consumed

scroll

open suspend fun scroll(scrollPriority: MutatePriority, block: suspend ScrollScope.() -> Unit): Unit

Call this function to take control of scrolling and gain the ability to send scroll events via ScrollScope.scrollBy. All actions that change the logical scroll position must be performed within a scroll block (even if they don't call any other methods on this object) in order to guarantee that mutual exclusion is enforced.

If scroll is called from elsewhere with the scrollPriority higher or equal to ongoing scroll, ongoing scroll will be canceled.

Public properties

isScrollInProgress

open val isScrollInProgressBoolean

Whether this ScrollableState is currently scrolling by gesture, fling or programmatically or not.

itemCountState

var itemCountStateMutableState<() -> Int>