Skip to content

Commit

Permalink
Boolti-235 refactor: IndicatorRange 네이밍 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
mangbaam committed Jun 26, 2024
1 parent fd1a3fc commit ecb8d1a
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ import com.nexters.boolti.presentation.theme.BooltiTheme
import kotlin.math.absoluteValue

private data class IndicatorRange(
@androidx.annotation.IntRange(from = 0) val start: Int,
@androidx.annotation.IntRange(from = 0) val end: Int,
) {
override val start: Int,
override val endInclusive: Int,
) : ClosedRange<Int> {
init {
check(start <= end)
check(start <= endInclusive)
}

val size: Int
get() = (end - start).absoluteValue + 1
get() = (endInclusive - start).absoluteValue + 1

operator fun invoke(): IntRange = start..end
operator fun minus(amount: Int): IndicatorRange = copy(start = start - amount, end = end - amount)
operator fun plus(amount: Int): IndicatorRange = copy(start = start + amount, end = end + amount)
override fun contains(value: Int): Boolean = value in start .. endInclusive
operator fun minus(amount: Int): IndicatorRange = copy(start = start - amount, endInclusive = endInclusive - amount)
operator fun plus(amount: Int): IndicatorRange = copy(start = start + amount, endInclusive = endInclusive + amount)
}

private class IndicatorUtil(
Expand Down Expand Up @@ -79,7 +79,7 @@ private class IndicatorUtil(
range: IndicatorRange,
offsetFraction: Float,
): Dp {
if (index in range()) return dotSize / 2
if (range.contains(index)) return dotSize / 2

val diff = when (index < range.start) {
true -> offsetFraction - index
Expand Down Expand Up @@ -147,7 +147,7 @@ fun InstagramIndicator(
mutableStateOf(
IndicatorRange(
start = s,
end = s + dotCount - 1,
endInclusive = s + dotCount - 1,
)
)
}
Expand All @@ -165,7 +165,7 @@ fun InstagramIndicator(
*/
val visibleRange by remember {
derivedStateOf {
IndicatorRange(range.start - 2, range.end + 2)
IndicatorRange(range.start - 2, range.endInclusive + 2)
}
}

Expand All @@ -181,7 +181,7 @@ fun InstagramIndicator(
LaunchedEffect(pagerState) {
snapshotFlow { pagerState.currentPage }.collect { page ->
range = when {
page > range.end -> range + 1
page > range.endInclusive -> range + 1
page < range.start -> range - 1
else -> range
}
Expand Down

0 comments on commit ecb8d1a

Please sign in to comment.