Skip to content

Commit

Permalink
[feat] #20 코드리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
kamja0510 committed Jan 16, 2025
1 parent bd31860 commit 88df6db
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,26 @@ fun BbangZipDatePicker(
modifier = Modifier.fillMaxWidth(),
) {
val years = DateConstant.YEARS_LIST
val yearPickerState = remember { mutableStateOf("") }
val yearPickerState by remember { mutableStateOf("") }
val startYear = currentDate.year.toInt() - DateConstant.YEAR_OF_TODAY

val months = DateConstant.MONTHS_LIST
val monthsPickerState = remember { mutableStateOf("") }
val monthsPickerState by remember { mutableStateOf("") }
val startMonth = currentDate.month.toInt() - 1

val days =
remember(yearPickerState.value, monthsPickerState.value) {
derivedStateOf {
val year = yearPickerState.value.filter { it.isDigit() }.toIntOrNull() ?: DateConstant.YEAR_OF_TODAY
val month = monthsPickerState.value.filter { it.isDigit() }.toIntOrNull() ?: 1
(1..getDaysInMonth(year, month)).map { it.toString() + "" }
}
remember(yearPickerState, monthsPickerState) {
val year = yearPickerState.filter { it.isDigit() }.toIntOrNull() ?: DateConstant.YEAR_OF_TODAY
val month = monthsPickerState.filter { it.isDigit() }.toIntOrNull() ?: 1
(1..getDaysInMonth(year, month)).map { it.toString() + "" }
}
val daysPickerState = remember { mutableStateOf("") }
val daysPickerState by remember { mutableStateOf("") }
val startDay = currentDate.day.toInt() - 1

LaunchedEffect(yearPickerState.value, monthsPickerState.value, daysPickerState.value) {
val year = yearPickerState.value.filter { it.isDigit() }
val month = monthsPickerState.value.filter { it.isDigit() }
val day = daysPickerState.value.filter { it.isDigit() }
LaunchedEffect(yearPickerState, monthsPickerState, daysPickerState) {
val year = yearPickerState.filter { it.isDigit() }
val month = monthsPickerState.filter { it.isDigit() }
val day = daysPickerState.filter { it.isDigit() }
onConfirm(
Date(
year = year,
Expand Down Expand Up @@ -79,7 +77,7 @@ fun BbangZipDatePicker(

Picker(
state = daysPickerState,
items = days.value,
items = days,
modifier = Modifier.weight(3f),
startIndex = startDay,
isCircular = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
Expand All @@ -41,13 +40,13 @@ import kotlinx.coroutines.flow.map
import org.android.bbangzip.ui.theme.BBANGZIPTheme
import org.android.bbangzip.ui.theme.BbangZipTheme
import org.android.bbangzip.ui.theme.defaultBbangZipColors
import timber.log.Timber

// isCircular : 무한 스크롤 여부
@Composable
fun Picker(
items: List<String>,
state: MutableState<String>,
state: String,
onItemChanged: (String) -> Unit = {},
modifier: Modifier = Modifier,
startIndex: Int = 0,
visibleItemsCount: Int = 5,
Expand Down Expand Up @@ -86,7 +85,6 @@ fun Picker(

val listState = rememberLazyListState(initialFirstVisibleItemIndex = listStartIndex)

Timber.tag("zz").d(listState.firstVisibleItemIndex.toString())
// 사용자가 스크롤을 멈출 때 애매하게 멈추지 않도록 하는 역할
val flingBehavior = rememberSnapFlingBehavior(lazyListState = listState)

Expand All @@ -112,7 +110,7 @@ fun Picker(
getItem(index + visibleItemsMiddle)
}
.distinctUntilChanged()
.collect { item -> state.value = item }
.collect { item -> onItemChanged(item) }
}

Box(modifier = modifier) {
Expand Down Expand Up @@ -147,7 +145,7 @@ fun Picker(
.fillMaxWidth()
.offset(y = itemHeightDp * visibleItemsMiddle)
.height(height = itemHeightDp)
.background(color = defaultBbangZipColors.fillAlternative_68645E_05),
.background(color = BbangZipTheme.colors.fillAlternative_68645E_05),
)
}
}
Expand All @@ -173,9 +171,9 @@ fun PickerPreview() {
modifier = Modifier.fillMaxSize(),
) {
val values = remember { (1..99).map { it.toString() } }
val valuesPickerState = remember { mutableStateOf("") }
val valuesPickerState by remember { mutableStateOf("") }
val units = remember { listOf("seconds", "minutes", "hours") }
val unitsPickerState = remember { mutableStateOf("") }
val unitsPickerState by remember { mutableStateOf("") }

Text(text = "Example Picker", modifier = Modifier.padding(top = 16.dp))
Row(modifier = Modifier.fillMaxWidth()) {
Expand All @@ -197,7 +195,7 @@ fun PickerPreview() {
}

Text(
text = "Interval: ${valuesPickerState.value} ${unitsPickerState.value}",
text = "Interval: $valuesPickerState $unitsPickerState",
modifier = Modifier.padding(vertical = 16.dp),
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.android.bbangzip.presentation.util.constant

object DateConstant {
const val YEAR_OF_TODAY = 2025
import java.time.LocalDate

object DateConstant {
val YEAR_OF_TODAY = LocalDate.now().year
val YEARS_LIST = (YEAR_OF_TODAY..2099).map { it.toString() + "" }
val MONTHS_LIST = (1..12).map { it.toString() + "" }
}

0 comments on commit 88df6db

Please sign in to comment.