-
Notifications
You must be signed in to change notification settings - Fork 37
๐ 2๋จ๊ณ - ํ์ด๋จผ์ธ (์นด๋ ๋ชฉ๋ก) #118
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
Conversation
change - CreditCardUiState ์ถ๊ฐ - Card ๋ชฉ๋ก ๊ฐ์์ ๋ฐ๋ฅธ ์ปดํฌ๋ํธ ๋ถ๋ฆฌ
laco-dev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ตฌํํด์ฃผ์ ๊ฒ ์ ๋ดค์ต๋๋ค.
๋ค๋น๊ฒ์ด์
์ ์ฌ์ฉํด์ฃผ์ ๊ฒ๊ณผ ๋๋ฉ์ธ ๋ก์ง์ ๊ผผ๊ผผํ ์์ฑํด์ฃผ์ ์ ์ธ์๊น๊ฒ ๋ณด์์ต๋๋ค.
๋ค๋ง ๋ทฐ๋ชจ๋ธ ํ๋๋ก ๋ชจ๋ ๋ก์ง์ ๋ค ๋ฃ์ ์ ์ ์กฐ๊ธ ์์ฌ์ ์ต๋๋ค.
๋ช๊ฐ์ง ์๊ฒฌ ๋จ๊ฒจ๋๋ ธ์ผ๋ ํ์ธ ํด์ฃผ์ธ์.
์ ๊ท ๊ฐ์ ์๊ฐ์ ๋ชจ๋ ์ข
๋ฃ๋์ด์ 24์๊ฐ ๋ด์ ๋ฆฌ๋ทฐ ๋ต๋ณ์ ๋๋ฆฌ์ง ๋ชปํ ํ๋ฅ ์ด ๋์ต๋๋ค.
์ด ์ ์ํด ๋ถํ๋๋ฆฝ๋๋ค.
| PaymentCardsScreen( | ||
| uiState = creditCardUiState, | ||
| onAddClick = { | ||
| navController.navigate(Destination.ADD_CARD.name) | ||
| }, | ||
| modifier = Modifier.fillMaxSize() | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํ๋์ ๋ทฐ๋ชจ๋ธ์์ ๋ชจ๋ ์ฒ๋ฆฌ๊ฐ ์ด๋ฃจ์ด ์ง๊ณ ์๋๋ฐ,
PaymentCardsScreen์ ์ํ ๋ทฐ๋ชจ๋ธ์ ๊ฐ์ง๋๋ก ๋ง๋ค์ด๋ณด์๋ฉด ์ข๊ฒ ์ต๋๋ค.
| interface Card { | ||
| val cardNumber: String | ||
| val expiredDate: String | ||
| val ownerName: String | ||
| val password: String | ||
|
|
||
| fun getFormattedCardNumber(): String | ||
| fun getFormattedExpiredDate(): String | ||
| } No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Card๋ฅผ ์ธํฐํ์ด์ค๋ก ๋ง๋ ์ด์ ๊ฐ ์์๊น์?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ดํ ์ ์ฉ/์ฒดํฌ/๋ฉค๋ฒ์ญ ์นด๋ ๋ฑ ์ฌ๋ฌ๊ฐ์ง ์นด๋๋ก ๋ถ๋ฆฌ๋ ์๋ ์์ ๊ฒ ๊ฐ๊ณ , ๊ฐ ๋ณ์๋ ์นด๋๋ผ๋ฉด ๊ธฐ๋ณธ์ ์ผ๋ก ๊ฐ์ง๋ ๊ฐ์ผ๋ก ๋ณด์ฌ interface ๋ก ์์ฑํด๋ดค์ต๋๋ค : )
| is CreditCardUiState.One -> OneCardScreen( | ||
| card = uiState.card, | ||
| modifier.padding(innerPadding), | ||
| onAddClick | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ด๋ค๊ฑด ์ด๋ฆ์ ์ง์ ํ๊ณ ์ด๋ค๊ฑด ์ํ๊ณ ํ๋ค๋ณด๋ฉด ๊ฐ๋ ์ฑ์ด ๋ง์ด ๋จ์ด์ง๋๋ค. ๋ชจ๋ ์ด๋ฆ์ ์ง์ ํด์ฃผ๋ฉด ์ด๋จ๊น์?
| if (uiState is CreditCardUiState.Many) { | ||
| Text( | ||
| text = stringResource(R.string.add), | ||
| fontSize = 18.sp, | ||
| fontWeight = FontWeight.Bold, | ||
| modifier = Modifier | ||
| .padding(end = 16.dp) | ||
| .clickable { onAddClick() } | ||
| ) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TopBar๊ฐ "์ถ๊ฐ" ๋ฒํผ๋ง ๊ฒฐ์ ํ๋ฉด ๋ ๊ฒ ๊ฐ์๋ฐ UiState์ ์์กดํ ํ์๊ฐ ์์๊น์?
| Box( | ||
| contentAlignment = Alignment.BottomCenter, | ||
| modifier = modifier | ||
| .shadow(8.dp) | ||
| .size(width = 208.dp, height = 124.dp) | ||
| .background( | ||
| color = Color(0xFF333333), | ||
| shape = RoundedCornerShape(5.dp), | ||
| ) | ||
| ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ชจ์์ ๋น๋กฏํ ์ฌ๋ฌ๊ฐ์ง ์ค์ ์ ์ํด์ Surface๋ฅผ ํ์ฉํด๋ณด์ ๋ ์ข์ต๋๋ค.
| LazyColumn( | ||
| modifier = modifier.padding(top = 12.dp), | ||
| verticalArrangement = Arrangement.spacedBy(36.dp), | ||
| horizontalAlignment = Alignment.CenterHorizontally | ||
| ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LazyColumn์ contentPaddding์ Modifier.padding()๊ณผ ์ด๋ค ์ฐจ์ด๊ฐ ์์๊น์?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
item์ ๊ฐ์๊ฐ ๋์ด๋ฌ์ ๋, ์ฐจ์ด๊ฐ ์๋์ ๊ฐ์ด ๋ณด์ด๋ ๊ฒ์ ํ์ธํ์ต๋๋ค!
contentPadding์ ์ ์ฉํ์ ๋์ ๊ฐ์ด ๋์ํ ๊ฒ์ด๋ผ ์๊ฐํ๋๋ฐ, UI ํ์ธ ์ ์ข ๋ ์ธ์ฌํ ๋ด์ผ๊ฒ ๋ค์๐ญ๐ญ
๊ผผ๊ผผํ ๋ฆฌ๋ทฐ ๊ฐ์ฌํฉ๋๋ค.
[Modifier.padding() ์ ์ฉ์]
[LazyColumn์ contentPadding ์ ์ฉ์]
| items(cards) { | ||
| PaymentCard( | ||
| cardNumber = it.getFormattedCardNumber(), | ||
| expiredDate = it.getFormattedExpiredDate(), | ||
| ownerName = it.ownerName | ||
| ) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
items๋ฅผ ์ง์ ํ ๋ key๊ฐ์ ๋ช
์ํ๋ ๊ฒ์ ๊ถ์ฅํฉ๋๋ค.
์ด key๊ฐ์ด ์ด๋ค ๋์์ ํ๋์ง๋ ๊ณต์ ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํด๋ณด์ธ์
https://developer.android.com/develop/ui/compose/lists?hl=ko#item-keys
| navigateToCardList = { | ||
| navController.popBackStack() | ||
| newCardViewModel.resetAddCard() | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ฐธ๊ณ ๋ก navigate { ... } ๋ฅผ ํ ๋ ํน์ Stack๊น์ง Popup์ ํ๋ ๊ธฐ๋ฅ์ ์ด์ฉํด์ ํ๋ฉด์ ์ด๋ํ๋ ๋ฐฉ๋ฒ๋ ์์ต๋๋ค.
| override fun getFormattedCardNumber(): String { | ||
| return cardNumber.chunked(4) | ||
| .mapIndexed { index, part -> | ||
| if (index in 2..3) { | ||
| "****" | ||
| } else { | ||
| part | ||
| } | ||
| } | ||
| .joinToString("-") | ||
| } | ||
|
|
||
| override fun getFormattedExpiredDate(): String { | ||
| return expiredDate.chunked(2).joinToString(" / ") | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํฌ๋งคํ ํด์ ๋ฌธ์์ด์ ์ถ๋ ฅํ๋ ๊ฒ์ ๋ชจ๋ธ์ด ํ ์ผ์ธ๊ฐ์? UI๊ฐ ํ ์ผ์ธ๊ฐ์?
change - Main Screen ๋ณ๋ก ViewModel ๋๋๊ธฐ (NewCardScreen, PaymentCardsScreen) - ์ปดํฌ์ ๋ธ ํจ์ ์ฌ์ฉ ์, ๋ชจ๋ ๋งค๊ฐ๋ณ์๋ช ์ง์ - PaymentCardsTopBar์์ CreditCardUiState ์์กด์ฑ ์ ๊ฑฐ - Box ๋์ Surface ์ฌ์ฉํ์ฌ ์คํ์ผ ์ง์ - LazyColumn items์ Key ์ง์ - CardNumber, ExpiredDate ํฌ๋งทํ ์ UI ๋ ์ด์ด์์ ์ฒ๋ฆฌํ๋๋ก ๋ณ๊ฒฝ
change - navigate ์ ํน์ Stack๊น์ง Popupํ๋ ๊ธฐ๋ฅ์ ์ด์ฉํ์ฌ ์ด๋ํ๋๋ก ์์
|
์๋
ํ์ธ์! 2๋จ๊ณ ๋ฆฌ๋ทฐ ์ฌํญ๋ค ๋ฐ์ํ์์ต๋๋ค! |
laco-dev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ณ ์ ๋ง์ผ์ จ์ต๋๋ค.
์ฌ๋ฌ๊ฐ์ง ๋ค ํด๋ณด๊ธฐ์๋ ๋ฏธ์ ๋ฒ์๋ ์๊ตฌ์ฌํญ์ด ์ ์ ํ์ง๋ ์์์ ์ง๊ธ์ ์ต์ํด์ง๋ ์ ๋๋ก๋ง ๋ด์ฃผ์๊ณ ๋์ค์ ๋ ์ฐ์ตํ์ค ๊ธฐํ๊ฐ ๋ง์๊ฑฐ์์.
| NavigateScreen( | ||
| newCardViewModel = newCardViewModel, | ||
| paymentCardViewModel = paymentCardViewModel | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hiltViewModel์ ์ฌ์ฉํ์ง ์์ผ๋ฉด ๋ทฐ๋ชจ๋ธ์ ์์์ ๋ชจ๋ ์ด๊ธฐํ ํ๊ณ ๋ด๋ ค์ค์ผ ํ ๊ฒ ๊ฐ๊ตฐ์.
์ง๊ธ์ ์๋์ง๋ง, ๋์ค์ ๋ ์ฐ์ตํ์ค ๋๋ ์ฐธ๊ณ ํด๋ณด์๋ฉด ๋์์ด ๋ ๊ฒ ๊ฐ์ต๋๋ค.
https://medium.com/kenneth-android/compose-hiltviewmodel-%EA%B3%BC-viewmodel-%EC%B0%A8%EC%9D%B4-6d5412efcb19
| @Preview | ||
| @Composable | ||
| private fun ManyPaymentCardsPreview() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ง์ด๋ํ ๋ถ๋ถ์ด์ง๋ง, Preview ํจ์ ์ด๋ฆ์ ๋งค๋ฒ ๋ง๋๋๊ฒ ๋ฒ๊ฑฐ๋ก์์ ์ ๋ ๊ฐ์ธ์ ์ผ๋ก ์ด๋ ๊ฒ ์์ฑํ๊ณ ๋ ํฉ๋๋ค.
ํ๋ง๋ค ์ฌ๋๋ง๋ค ๋ค๋ฅด๋๋ผ๊ตฌ์
@Preview(name = "...")
fun Preview1()
...
2๋จ๊ณ ๋ฆฌ๋ทฐ ์ ๋ถํ๋๋ฆฝ๋๋ค ๐โโ๏ธ
[ ๊ธฐ๋ฅ ์ถ๊ฐ ์ฌํญ ]
Screen shot
Screen_recording_20250323_232847.mp4