mertceyhan
05/09/2022, 10:13 AMhttps://user-images.githubusercontent.com/15737675/38328329-e7008c06-384a-11e8-8449-9f2e396d2bc5.gif▾
Tin Tran
05/09/2022, 10:17 AM@ExperimentalPagerApi
@OptIn(ExperimentalAnimationApi::class)
@Composable
fun PagerIndicator(
state: PagerState,
modifier: Modifier = Modifier,
activeColor: Color = GolftecGreen,
inActiveColor: Color = Color.White,
activeWidth: Dp = 12.dp,
inActiveSize: Dp = 4.dp,
indicatorSpacing: Dp = 3.dp
) {
Row(modifier = modifier) {
for (i in 0 until state.pageCount) {
val isActive = i == state.currentPage
val backgroundColor = if (isActive) {
lerp(
activeColor,
inActiveColor,
abs(state.currentPageOffset).coerceIn(0f, 1f)
)
} else if (i == state.targetPage) {
lerp(
inActiveColor,
activeColor,
abs(state.currentPageOffset).coerceIn(0f, 1f)
)
} else {
inActiveColor
}
val width = if (isActive)
(activeWidth * (1 - abs(state.currentPageOffset))).coerceIn(
inActiveSize,
activeWidth
)
else if (i == state.targetPage)
(activeWidth * abs(state.currentPageOffset)).coerceIn(inActiveSize, activeWidth)
else
inActiveSize
Box(
modifier = Modifier
.clip(RoundedCornerShape(inActiveSize))
.width(width)
.height(inActiveSize)
.background(backgroundColor)
)
Spacer(modifier = Modifier.width(indicatorSpacing))
}
}
}
mertceyhan
05/09/2022, 10:19 AM@ExperimentalPagerApi
@Composable
fun WormHorizontalPagerIndicator(
pagerState: PagerState,
modifier: Modifier = Modifier,
activeColor: Color = LocalContentColor.current.copy(alpha = LocalContentAlpha.current),
inactiveColor: Color = activeColor.copy(ContentAlpha.disabled),
indicatorWidth: Dp = 8.dp,
activeIndicatorWidth: Dp = 25.dp,
indicatorHeight: Dp = indicatorWidth,
spacing: Dp = indicatorWidth,
indicatorShape: Shape = CircleShape,
) {
Box(
modifier = modifier,
contentAlignment = Alignment.CenterStart
) {
Row(
horizontalArrangement = Arrangement.spacedBy(spacing),
verticalAlignment = Alignment.CenterVertically,
) {
repeat(pagerState.pageCount) { index ->
val currentPage = pagerState.currentPage
val width by animateDpAsState(targetValue = if (currentPage == index) activeIndicatorWidth else indicatorWidth)
val color by animateColorAsState(targetValue = if (currentPage == index) activeColor else inactiveColor)
Box(
Modifier
.size(
width = width,
height = indicatorHeight
)
.background(
color = color,
shape = indicatorShape
)
)
}
}
}
}
Tin Tran
05/09/2022, 10:22 AMmertceyhan
05/09/2022, 10:25 AMChris Sinco [G]
05/09/2022, 5:41 PMmertceyhan
05/11/2022, 3:25 PM