1515
1616package com.uravgcode.chooser.tutorial.presentation.component
1717
18- import androidx.compose.animation.core.animateDpAsState
19- import androidx.compose.animation.core.animateFloatAsState
2018import androidx.compose.foundation.background
2119import androidx.compose.foundation.layout.Arrangement
2220import androidx.compose.foundation.layout.Box
@@ -27,9 +25,9 @@ import androidx.compose.foundation.pager.PagerState
2725import androidx.compose.foundation.shape.CircleShape
2826import androidx.compose.material3.MaterialTheme
2927import androidx.compose.runtime.Composable
30- import androidx.compose.runtime.getValue
3128import androidx.compose.ui.Modifier
3229import androidx.compose.ui.unit.dp
30+ import kotlin.math.absoluteValue
3331
3432@Composable
3533fun PageIndicator (
@@ -40,16 +38,15 @@ fun PageIndicator(
4038 modifier = modifier,
4139 horizontalArrangement = Arrangement .spacedBy(8 .dp)
4240 ) {
43- repeat(pagerState.pageCount) { index ->
44- val isSelected = pagerState.currentPage == index
41+ val page = pagerState.currentPage
42+ val offset = pagerState.currentPageOffsetFraction
4543
46- val width by animateDpAsState(
47- targetValue = if (isSelected) 18 .dp else 8 .dp,
48- )
44+ repeat(pagerState.pageCount) { index ->
45+ val distance = (index - (page + offset)).absoluteValue
46+ val percentage = ( 1f - distance).coerceAtLeast( 0f )
4947
50- val alpha by animateFloatAsState(
51- targetValue = if (isSelected) 1f else 0.5f ,
52- )
48+ val width = 8 .dp + (10 .dp * percentage)
49+ val alpha = 0.5f + (0.5f * percentage)
5350
5451 Box (
5552 modifier = Modifier
0 commit comments