< /p>
Код: Выделить всё
CenterZoomedCarousel(
items = pokemons,
spacing = 4.dp,
itemSize = itemSize,
zoomItemSize = itemSize * 3f,
modifier = Modifier.height(200.dp),
scrollType = kr.co.carousel.CarouselScrollType.INFINITE
) { carouselItemState ->
val item = carouselItemState.item
if (carouselItemState.isFocus) name = item.second
Card {
Column(
modifier = Modifier
.background(Color.White)
.padding(12.dp)
) {
Image(
painter = rememberAsyncImagePainter(item.first),
contentDescription = item.second,
modifier = carouselItemState.animatedModifier
)
}
}
}
@Composable
fun CenterZoomedCarousel(
...
CarouselLazyRow(
modifier = Modifier
.fillMaxWidth(),
lazyCarouselState = carouselState,
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(spacing)
) {
carouselItems(items, scrollType) { item, isCurrentPage ->
val targetSize = remember(isCurrentPage) {
if (isCurrentPage) zoomItemSize else itemSize
}
val targetAlpha = remember(isCurrentPage) {
if (isCurrentPage) 1f else unfocusedAlpha
}
val animatedSize by animateDpAsState(
targetValue = targetSize,
label = "animatedSize",
finishedListener = { carouselState.setAnimationEnd(true) }
)
val animatedAlpha by animateFloatAsState(targetAlpha, label = "animatedAlpha")
content(
CarouselItemState(
item,
Modifier
.size(animatedSize)
.alpha(animatedAlpha),
isCurrentPage
)
)
}
}
Код: Выделить всё
data class CarouselItemState(
val item: T,
val animatedModifier: Modifier,
val isFocus: Boolean,
)
из-за чего у меня возникает ощущение, что эта реализация может не соответствовать общепринятым практикам.
Вам такой подход тоже покажется странным?
Я буду признателен за отзывы о том, кажется ли это нетрадиционным и
Подробнее здесь: https://stackoverflow.com/questions/793 ... is-unusual
Мобильная версия