androidx.compose.material3.carousel

HorizontalMultiBrowseCarousel

Composable function

A carousel is a horizontal list of items, usually photos, that the user swipes through.

A carousel with large and small items
A carousel with large and small items
val colors = listOf(Color(0xFF8E6CEF), Color(0xFFEF6C8E), Color(0xFF6CB4EF), Color(0xFF6CEF9B), Color(0xFFEFC36C))
HorizontalMultiBrowseCarousel(
    state = rememberCarouselState { colors.size },
    preferredItemWidth = 186.dp,
    itemSpacing = 8.dp,
    modifier = Modifier.width(360.dp).height(200.dp),
) { index ->
    // maskClip gives each item the rounded shape that changes while scrolling.
    Box(
        Modifier.fillMaxSize().maskClip(MaterialTheme.shapes.extraLarge).background(colors[index]),
        contentAlignment = Alignment.Center,
    ) { Text("Photo ${index + 1}", color = Color.White) }
}

Inside each item, use Modifier.maskClip(shape) instead of clip. It lets the carousel change the item's shape while it scrolls.

Items of the same width
Items of the same width
val colors = listOf(Color(0xFF8E6CEF), Color(0xFFEF6C8E), Color(0xFF6CB4EF), Color(0xFF6CEF9B))
HorizontalUncontainedCarousel(
    state = rememberCarouselState { colors.size },
    itemWidth = 150.dp,
    itemSpacing = 8.dp,
    modifier = Modifier.width(360.dp).height(160.dp),
) { index ->
    Box(Modifier.fillMaxSize().maskClip(MaterialTheme.shapes.extraLarge).background(colors[index]))
}

Parameters

@Composable
fun HorizontalMultiBrowseCarousel(
    state: CarouselState,
    preferredItemWidth: Dp,
    modifier: Modifier = Modifier,
    itemSpacing: Dp = 0.dp,
    flingBehavior: TargetedFlingBehavior = CarouselDefaults.singleAdvanceFlingBehavior(state = state),
    userScrollEnabled: Boolean = true,
    minSmallItemWidth: Dp = CarouselDefaults.MinSmallItemSize,
    maxSmallItemWidth: Dp = CarouselDefaults.MaxSmallItemSize,
    contentPadding: PaddingValues = PaddingValues(0.dp),
    content: @Composable CarouselItemScope.(itemIndex: Int) -> Unit,
)

state: CarouselStateRequired

The scroll position and item count. Create it with rememberCarouselState { itemCount }.

preferredItemWidth: DpRequired

The width of the large item. The carousel fits as many as it can, and fills the rest with smaller items.

modifier: ModifierOptional

Default: Modifier

Changes size, padding, or position. Set the height here.

itemSpacing: DpOptional

Default: 0.dp

The gap between items.

flingBehavior: TargetedFlingBehaviorOptional

Default: CarouselDefaults.singleAdvanceFlingBehavior(state = state)

How the carousel moves after a swipe: one item at a time, or freely.

userScrollEnabled: BooleanOptionalSince 1.9

Default: true

Set to false to stop the user from scrolling.

minSmallItemWidth: DpOptional

Default: CarouselDefaults.MinSmallItemSize

The narrowest a small item can be.

maxSmallItemWidth: DpOptional

Default: CarouselDefaults.MaxSmallItemSize

The widest a small item can be.

contentPadding: PaddingValuesOptional

Default: PaddingValues(0.dp)

Space before the first and after the last item.

content: @Composable CarouselItemScope.(itemIndex: Int) -> UnitRequired

Draws one item. Receives the item index.

Carousel types