#1 ๊ฐ์
์คํฌ๋กค ๊ด๋ จํด์๋ ํ์๋ฆ ๋์๋ค. ๋ณธ ๊ฒ์๊ธ์์ LazyColumn์ ๊ฐ ์์ดํ
์ Card๋ก ๊ฐ์ธ๊ณ ์ฝ๊ฐ์ ๋์์ธ์ ์์ ์ ํ ๊ฒ์ด๋ค. ๋ณธ ๊ฒ์๊ธ๊น์งํด์ ํ๋ก ํธ์๋๋ ์ค๊ฐ ๋งบ์์ ํ ๊ฒ์ด๊ณ ๋ค์ ๊ฒ์๊ธ๋ถํฐ๋ ์๋ง ๋ฐฑ์๋ ๊ตฌํ์ผ๋ก ๋์ด๊ฐ๋ฏ ์ถ๋ค.
#2 ์ฝ๋
#2-1 (ํ ์ก๊ธฐ) Card()
...
@Composable
fun NutrientScreen(
...
) {
LaunchedEffect(key1 = true) {
// State ์ด๊ธฐํ
...
// ViewModel๋ก๋ถํฐ ๋ฐ์ ์ด๋ฒคํธ ์ฒ๋ฆฌ
...
}
LaunchedEffect(key1 = viewModel.isInitialized.value) {
...
}
LazyColumn(
...
) {
val dailyMeals = viewModel.nutrientScreenState.value.dailyMeals
items(dailyMeals) { dailyMeal ->
Card(
modifier = Modifier
.fillMaxWidth()
.padding(
start = 8.dp,
top = 8.dp,
end = 8.dp,
),
elevation = CardDefaults.cardElevation(8.dp)
) {
Text(
...
)
}
}
}
}
item์ Card๋ก ๊ฐ์ผ๋ค. ๋๋น๋ ๋ถ๋ชจ์ ์ต๋ ๋๋น๋ฅผ ์ฐจ์งํ๊ฒ ๋๊ณ ์ ๋นํ padding์ ๋ฃ์ด์ฃผ์๋ค. ๋, Card์ ํน์ง์ธ elevation๋ ์ ๋นํ ๊ฐ์ผ๋ก ๋ฃ์ด์ฃผ์๋ค.
#2-2 (๋ชจ์ ์ก๊ธฐ ์ค๋น) utils ํจํค์ง ๋ง๋ค๊ณ DateFormatter.kt ์์ฑ
// package com.example.nutri_capture_new.utils
import java.time.LocalDate
import java.time.format.TextStyle
import java.util.Locale
object DateFormatter {
fun formatDateForNutrientScreen(date: LocalDate): String {
val month = date.monthValue
val day = date.dayOfMonth
val dayOfWeek = date.dayOfWeek.getDisplayName(TextStyle.FULL, Locale.KOREAN)
return "${month}์ ${day}์ผ $dayOfWeek"
}
}
"2024-10-17"์ ๊ฐ์ ํ์์ผ๋ก ํ์๋๋ ๋ ์ง๋ฅผ "10์ 17์ผ ๋ชฉ์์ผ"๊ณผ ๊ฐ์ ํ์์ผ๋ก ๋ณํ์์ผ์ฃผ๋ ํจ์๋ค.
#2-3 (๋ชจ์ ์ก๊ธฐ) Text() ์์ ๋ฐ Column์ผ๋ก ๊ฐ์ธ๊ธฐ
...
@Composable
fun NutrientScreen(
...
) {
LaunchedEffect(key1 = true) {
...
}
LaunchedEffect(key1 = viewModel.isInitialized.value) {
...
}
LazyColumn(
state = listState,
modifier = Modifier.fillMaxSize()
) {
val dailyMeals = viewModel.nutrientScreenState.value.dailyMeals
items(dailyMeals) { dailyMeal ->
Card(
...
) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
) {
Text(
text = DateFormatter.formatDateForNutrientScreen(dailyMeal.date),
modifier = Modifier.fillMaxWidth(),
fontSize = 15.sp,
textAlign = TextAlign.End
)
}
}
}
}
}
LazyColumn()์ ๋ฐฐ๊ฒฝ์๊ณผ Text()์ ๊ธ์์์ ์ง์ ํ๋ ์ฝ๋๋ฅผ ์ญ์ ํ๋ค. ์ฆ ๊ธฐ๋ณธ๊ฐ ์์ผ๋ก ๋๋ค.
Text()์์ ๊ธ์ ํฌ๊ธฐ๋ฅผ 15.sp๋ก ์ค์ด๊ณ ๊ธฐ๋ณธ๊ฐ์ธ ์ข์ธก ์ ๋ ฌ ์ค์ ์ ์ฐ์ธก ์ ๋ ฌ๋ก ๋ฐ๊ฟจ๋ค. ๋ #2-2์ ํจ์๋ฅผ ํ์ฉํด, ๋ ์ง๊ฐ "10์ 17์ผ ๋ชฉ์์ผ"๊ณผ ๊ฐ์ ํ์์ผ๋ก ํ์๋๋๋ก ์์ ํ๋ค.
๋ง์ง๋ง์ผ๋ก ์์ ํ Text()๋ฅผ Column()์ผ๋ก ๊ฐ์ผ๋ค. Column์๋ padding์ 8.dp๋ก ์ง์ ํ๋ค.
#2-4 ์ํ ์ปจํ ์ธ Column์ ๋ฃ์ด์ฃผ๊ธฐ
...
@Composable
fun NutrientScreen(
scope: CoroutineScope,
snackbarHostState: SnackbarHostState,
viewModel: NutrientViewModel = viewModel<NutrientViewModel>(),
listState: LazyListState = rememberLazyListState()
) {
LaunchedEffect(key1 = true) {
// State ์ด๊ธฐํ
...
// ViewModel๋ก๋ถํฐ ๋ฐ์ ์ด๋ฒคํธ ์ฒ๋ฆฌ
...
}
LaunchedEffect(key1 = viewModel.isInitialized.value) {
...
}
LazyColumn(
...
) {
...
items(dailyMeals) { dailyMeal ->
Card(
...
) {
Column(
...
) {
Text(
...
)
SampleContent(
text = "Sample ์์ ์ ๋ณด",
modifier = Modifier
.fillMaxWidth()
.height(100.dp),
scope = scope,
snackbarHostState = snackbarHostState
)
}
}
}
}
}
Column()์ Text() ํ๋๋ง ์๋ ๊ฑด ํ์ ํ๋๊น, MainActivity.kt์ ์ ์ํด๋์๋ SampleContent()๋ฅผ ๋ฃ์ด์ค๋ค.
#3 ์์ฝ
LazyColumn์ ์์ดํ
์ Card()๋ก ๊ฐ์ธ๊ณ , ๋์์ธ์ ์ผ๋ก ์ด์ง ๋ค๋ฌ์๋ค.
#4 ์์ฑ๋ ์ฑ
#4-1 ์คํฌ๋ฆฐ์ท

#4-2 ์ด ๊ฒ์๊ธ ์์ ์ Commit
GitHub - Kanmanemone/nutri-capture-new
Contribute to Kanmanemone/nutri-capture-new development by creating an account on GitHub.
github.com
#4-3 ๋ณธ ํ๋ก์ ํธ์ ๊ฐ์ฅ ์ต์ Commit
GitHub - Kanmanemone/nutri-capture-new
Contribute to Kanmanemone/nutri-capture-new development by creating an account on GitHub.
github.com