Carousel

A swipeable pager-based carousel with horizontal and vertical orientations, auto-scroll, dot indicators, fixed-size pages, and optional external state control.

Carousel wraps Compose Foundation's HorizontalPager / VerticalPager with snapping behavior, an animated dot indicator, and optional auto-scroll. Each page receives a zero-based position index via the content lambda. Pass an external PagerState to drive the carousel programmatically.

Basic usage

Auto scroll

Set autoScroll = true to advance pages automatically. Use autoScrollDelayMillis to control the pause between transitions. Auto-scroll pauses while the user is dragging.

Fixed-width pages

Use pageSize = PageSize.Fixed(...) to show partial adjacent pages and hint at horizontal scrollability. Pair with itemSpacing for the gap between pages.

API reference

ParameterTypeDefaultDescription
containerModifierModifierModifierApplied to the outer Column that wraps the pager and indicator.
modifierModifierModifierApplied to the pager itself.
statePagerState?nullExternal pager state. An internal state is created when null.
autoScrollBooleanfalseWhen true, advances pages automatically after autoScrollDelayMillis. Pauses during drag.
autoScrollDelayMillisLong3000Milliseconds between auto-scroll advances.
orientationCarouselOrientationCarouselOrientation.HorizontalScroll axis.
componentSpacingDp8.dpVertical gap between the pager and the indicator row.
contentPaddingPaddingValuesPaddingValues(12.dp, 0.dp)Padding applied inside the pager viewport, revealing adjacent pages.
showIndicatorBooleanfalseWhether to render the dot indicator below the pager.
indicatorStyleIndicatorStyleCarouselDefaults.carouselIndicator()Visual style of the dot indicator.
itemSpacingDp8.dpGap between individual pages.
itemCountIntTotal number of pages.
pageSizePageSizePageSize.FillSize strategy for each page. Use PageSize.Fixed(dp) for partial-page peek.
onItemChanged((Int) -> Unit)?nullCallback invoked with the new page index whenever the current page changes.
content@Composable PagerScope.(position: Int) -> UnitContent for each page, keyed by zero-based position.

CarouselOrientation

ValueDescription
HorizontalPages scroll left and right (default).
VerticalPages scroll up and down.

IndicatorStyle

FieldTypeDescription
activeColorColorFill color of the active dot.
inactiveColorColorFill color of inactive dots.
activeSizeDpDiameter of the active dot.
inactiveSizeDpDiameter of inactive dots.
shapeShapeShape of each dot. Defaults to CircleShape.
spacingDpPadding around each dot.

CarouselDefaults

MemberDescription
carouselIndicator()Returns an IndicatorStyle using foreground (active) and mutedForeground (inactive) with 12 dp / 8 dp sizes and CircleShape.
Edit this page on GitHub