Skip to content

Commit a476663

Browse files
committed
improve page indicator animation
1 parent be3e961 commit a476663

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

app/src/main/java/com/uravgcode/chooser/tutorial/presentation/TutorialScreen.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
package com.uravgcode.chooser.tutorial.presentation
1717

18-
import androidx.compose.foundation.ExperimentalFoundationApi
1918
import androidx.compose.foundation.layout.Arrangement
2019
import androidx.compose.foundation.layout.Box
2120
import androidx.compose.foundation.layout.Column
@@ -50,7 +49,6 @@ import kotlinx.coroutines.launch
5049
import kotlin.math.absoluteValue
5150

5251
@Composable
53-
@OptIn(ExperimentalFoundationApi::class)
5452
fun TutorialScreen(onComplete: () -> Unit) {
5553
val coroutineScope = rememberCoroutineScope()
5654
val pagerState = rememberPagerState(pageCount = { pagerContent.size })

app/src/main/java/com/uravgcode/chooser/tutorial/presentation/component/PageIndicator.kt

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
package com.uravgcode.chooser.tutorial.presentation.component
1717

18-
import androidx.compose.animation.core.animateDpAsState
19-
import androidx.compose.animation.core.animateFloatAsState
2018
import androidx.compose.foundation.background
2119
import androidx.compose.foundation.layout.Arrangement
2220
import androidx.compose.foundation.layout.Box
@@ -27,9 +25,9 @@ import androidx.compose.foundation.pager.PagerState
2725
import androidx.compose.foundation.shape.CircleShape
2826
import androidx.compose.material3.MaterialTheme
2927
import androidx.compose.runtime.Composable
30-
import androidx.compose.runtime.getValue
3128
import androidx.compose.ui.Modifier
3229
import androidx.compose.ui.unit.dp
30+
import kotlin.math.absoluteValue
3331

3432
@Composable
3533
fun 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

Comments
 (0)