Skip to content

Commit ea83e16

Browse files
committed
Make page indicator scollable
1 parent 468f421 commit ea83e16

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

app/src/main/java/com/amrdeveloper/linkhub/ui/components/PagerIndicator.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.amrdeveloper.linkhub.ui.components
22

33
import androidx.compose.animation.core.animateDpAsState
44
import androidx.compose.foundation.background
5+
import androidx.compose.foundation.clickable
56
import androidx.compose.foundation.layout.Arrangement
67
import androidx.compose.foundation.layout.Box
78
import androidx.compose.foundation.layout.Row
@@ -12,13 +13,15 @@ import androidx.compose.foundation.pager.PagerState
1213
import androidx.compose.foundation.shape.CircleShape
1314
import androidx.compose.runtime.Composable
1415
import androidx.compose.runtime.getValue
16+
import androidx.compose.runtime.rememberCoroutineScope
1517
import androidx.compose.ui.Alignment
1618
import androidx.compose.ui.Modifier
1719
import androidx.compose.ui.draw.clip
1820
import androidx.compose.ui.graphics.Color
1921
import androidx.compose.ui.res.colorResource
2022
import androidx.compose.ui.unit.dp
2123
import com.amrdeveloper.linkhub.R
24+
import kotlinx.coroutines.launch
2225

2326
@Composable
2427
fun PagerIndicator(
@@ -27,6 +30,7 @@ fun PagerIndicator(
2730
selectedIndicatorColor: Color = colorResource(R.color.light_blue_200),
2831
unSelectedIndicatorColor: Color = colorResource(R.color.light_blue_900),
2932
) {
33+
val coroutineScope = rememberCoroutineScope()
3034
Row(
3135
modifier = modifier
3236
.fillMaxWidth()
@@ -40,7 +44,7 @@ fun PagerIndicator(
4044
else unSelectedIndicatorColor
4145

4246
val size by animateDpAsState(
43-
targetValue = if (isCurrentPage) 10.dp else 8.dp, label = "Indicator dor color"
47+
targetValue = if (isCurrentPage) 10.dp else 8.dp, label = "Indicator dot size"
4448
)
4549

4650
Box(
@@ -49,7 +53,12 @@ fun PagerIndicator(
4953
.clip(CircleShape)
5054
.background(indicatorColor)
5155
.size(size)
56+
.clickable {
57+
coroutineScope.launch {
58+
pagerState.animateScrollToPage(iteration)
59+
}
60+
}
5261
)
5362
}
5463
}
55-
}
64+
}

0 commit comments

Comments
 (0)