MultiAspectCarouselScope
Creates a multi-apsect carousel scope that includes all related methods for creating a
MultiAspectCarouselScope
Composable Component
Creates a multi-apsect carousel scope that includes all related methods for creating a multi-aspect carousel.
Common
@Composable
fun MultiAspectCarouselScope(content: @Composable MultiAspectCarouselScope.() -> Unit)
Code Examples
MultiAspectCarouselLazyRowSample
@OptIn(ExperimentalMaterial3Api::class)
@Preview
@Composable
fun MultiAspectCarouselLazyRowSample() {
data class CarouselItem(
val id: Int,
@DrawableRes val imageResId: Int,
@StringRes val contentDescriptionResId: Int,
val mainAxisSize: Dp,
)
val items =
listOf(
CarouselItem(
0,
R.drawable.carousel_image_1,
R.string.carousel_image_1_description,
305.dp,
),
CarouselItem(
1,
R.drawable.carousel_image_2,
R.string.carousel_image_2_description,
205.dp,
),
CarouselItem(
2,
R.drawable.carousel_image_3,
R.string.carousel_image_3_description,
275.dp,
),
CarouselItem(
3,
R.drawable.carousel_image_4,
R.string.carousel_image_4_description,
350.dp,
),
CarouselItem(
4,
R.drawable.carousel_image_5,
R.string.carousel_image_5_description,
100.dp,
),
)
MultiAspectCarouselScope {
val state = rememberLazyListState()
LazyRow(
state = state,
contentPadding = PaddingValues(16.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier.fillMaxWidth().height(221.dp),
) {
itemsIndexed(items) { i, item ->
val drawInfo = remember { MultiAspectCarouselItemDrawInfo(i, state) }
Image(
painter = painterResource(id = item.imageResId),
contentDescription = stringResource(item.contentDescriptionResId),
modifier =
Modifier.width(item.mainAxisSize)
.height(205.dp)
.maskClip(MaterialTheme.shapes.extraLarge, drawInfo),
contentScale = ContentScale.Crop,
)
}
}
}
}
Create your own Component Library
Material Components are meant to be used as is and they do not allow customizations. To build your own Jetpack Compose component library use Compose Unstyled