Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] PageIndicator component 추가 #33

Merged
merged 3 commits into from
Feb 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.nexters.ilab.core.ui.component

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import com.nexters.ilab.android.core.designsystem.theme.Blue600
import com.nexters.ilab.android.core.designsystem.theme.Gray300
import com.nexters.ilab.core.ui.ComponentPreview

@OptIn(ExperimentalFoundationApi::class)
@Composable
internal fun PagerIndicator(pagerState: PagerState) {
Row(
modifier = Modifier
.wrapContentHeight()
.fillMaxWidth(),
horizontalArrangement = Arrangement.Center,
) {
repeat(pagerState.pageCount) { iteration ->
val color = if (pagerState.currentPage == iteration) Blue600 else Gray300
val modifier = if (pagerState.currentPage == iteration) Modifier.padding(4.dp)
.clip(CircleShape)
.width(18.dp)
.background(color)
.size(7.dp) else Modifier.padding(4.dp)
.clip(CircleShape)
.background(color)
.size(7.dp)
Box(modifier = modifier)
}
}
}

@OptIn(ExperimentalFoundationApi::class)
@ComponentPreview
@Composable
internal fun PagerIndicatorPreview() {
val pagerState = rememberPagerState(pageCount = { 4 })
PagerIndicator(pagerState)
}
Loading