-
Notifications
You must be signed in to change notification settings - Fork 36
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
๐ 4๋จ๊ณ - ํ์ด๋จผ์ธ (์นด๋ ์์ ) #98
base: ethanchaee
Are you sure you want to change the base?
Conversation
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.
4๋จ๊ณ ๋ฏธ์
๊ณ ์ ๋ง์ผ์
จ์ด์!
์ฌ๋ฌ ์ฝ๋ฉํธ ๋จ๊ฒจ๋์์ผ๋ ํ์ธ๋ถํ๋๋ ค์ :)
๋ฏธ์
์ ์ด๋ง ๋ง๋ฌด๋ฆฌ ์ง๊ณ ์ถ์ผ์๋ค๋ฉด ์ฝ๋ฉํธ๋ ๋ฉ์์ง ๋จ๊ฒจ์ฃผ์๊ณ , ๋ ์๋ํ๊ณ ์ถ์ผ์ ๊ฒ์ด ์์ผ์๋ค๋ฉด ๋ฐ์ ํ ๋ค์ ๋ฆฌ๋ทฐ์์ฒญ ๋ถํ๋๋ ค์!
@Composable | ||
fun CardAddScreen( | ||
fun CardAddModifyScreen( | ||
isModify: Boolean, |
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.
์นด๋ ์์ ํ๊ธฐ Screen๊ณผ ์๋ก ๋ง๋๋ Screen ์ปดํฌ๋ํธ๋ ์์ ํ ๋์ผํ๋,
๊ธฐ์กด ๋ง๋ค์ด ๋ Stateless Screen ์ปดํฌ๋ํธ๋ฅผ ์์ , ์ถ๊ฐ ์กํฐ๋นํฐ์์ ํ์ฉํ๋ ํํ๋ก ๊ตฌ์ฑํด๋ณด๋ ๊ฑด ์ด๋จ๊น์?
Stateless Screen ์ปดํฌ๋ํธ๋ฅผ ๊ฐ๊ฐ ๊ฐ์ง๋ Stateful Screen์ด ๋ ๊ฐ ๋ง๋ค์ด์ง ์๋ ์๊ฒ ์ด์.
๊ทธ๋ ๋ค๋ฉด ๊ฐ stateful Screen์ ํ
์คํธํ ๋๋ ์ฉ์ดํ ๊ฑฐ๋ผ ์๊ฐํด์!
private fun CardListScreenPreview2() { | ||
val cards = listOf( |
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_๊ทธ์ปดํฌ๋ํธ์ํน์ง
์ด๋ฐ ํํ๋ก ์ง๋ ํธ์ด์์.
ex) CardListPreview_ManyCards()
Preview๋ ๋๋ง ๋ ๊ฒ์ ๋ณด๋๋ผ๋ ์ด๋ค ํน์ง์ ๊ฐ์ง๋์ง ์๊ธฐ ์ด๋ ค์ธ ๋, Preview์ ํจ์๋ช ์ ์ข ๋ ๊ทธ ํน์ง์ ๋ฌ์ฌํด์ ์กฐ๊ธ์ด๋ผ๋ Preview๋ฅผ ์ฝ๊ฒ ํ์ ํ ์ ์๊ฒ ๋์์ฃผ๋ ค๊ณ ์ด๋ ๊ฒ ์์ฑํ๋ ํธ์ด์์ :)
Card( | ||
modifier = Modifier.clickable(enabled = enabled) { context.toCardModify(cardId = model.id) }, | ||
backgroundColor = cardColor, | ||
) { |
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.
์นด๋ ์ปดํฌ๋ํธ ์์ฒด์ ํน์ ๊ธฐ๋ฅ์ด ๋ค์ด๊ฐ๋ฉด ์ฌํ์ฉ์ด ์ด๋ ต๋ค๊ณ ์๊ฐํด์.
ํด๋ฆญํ ์ ์๋ ๋ฆฌ์ค๋๋ฅผ ์ธ๋ถ์์ ๋ฐ๊ฑฐ๋, Modifier๋ฅผ ์ธ๋ถ์์ ๋ฐ๋๋ก ๊ตฌ์ฑํด๋ณด๋ ๊ฑด ์ด๋จ๊น์?
@Composable | ||
private fun CardNumberInputField( | ||
value: String, | ||
onValueChange: (String) -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
CardInputField( | ||
value = value, | ||
onValueChange = onValueChange, | ||
maxLength = 16, | ||
labelText = stringResource(R.string.card_number_label), | ||
placeHolderText = stringResource(R.string.card_number_placeholder), | ||
keyboardType = KeyboardType.Number, | ||
visualTransformation = CardNumberVisualTransformation(), | ||
) | ||
} | ||
|
||
@Composable | ||
private fun OwnerNameInputField( | ||
value: String, | ||
onValueChange: (String) -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
CardInputField( | ||
value = value, | ||
onValueChange = onValueChange, | ||
maxLength = 20, | ||
labelText = stringResource(R.string.card_owner_name_label), | ||
placeHolderText = stringResource(R.string.card_owner_name_placeholder), | ||
keyboardType = KeyboardType.Text, | ||
visualTransformation = VisualTransformation.None, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun ExpireDateInputField( | ||
value: String, |
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.
์ด ์ปดํฌ๋ํธ๋ค์ ํ์ผ ๋ถ๋ฆฌํ๋ค๋ฉด ํ ์คํธ๋ ์ปดํฌ๋ํธ๋ณ๋ก ๊ตญ์์ ์ผ๋ก ๊ตฌ์ฑํด๋ณผ ์ ์๊ฒ ์ด์!
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 (cardsUiState is CardsUiState.Many) { | ||
CardListTopBar(onAddClick = { context.toCardAdd() }) | ||
} else { |
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.
์ด๋ถ๋ถ์ ์ง๋ ๋ฆฌ๋ทฐ์์ ๋์ณค๋ค์!
์ด๋ถ๋ถ๋, ํน์ ํด๋ฆญ ์ด๋ฒคํธ์ ์ข
์์ ์ด ๋๋, ํด๋ฆญ ์ด๋ฒคํธ๋ ์ธ๋ถ์์ ์ฃผ์
๋ฐ๋๋ก ํ๋ ๊ฒ์ ์ด๋จ๊น์?
) { | ||
val context = LocalContext.current |
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.
์ฌ๊ธฐ context๋ ์ค์๋ก ์ถ๊ฐ๋ ๊ฑธ๊น์ ?_?
Text( | ||
text = CardInputType.CardNumber.maskingText(model.number), | ||
text = cardNumberMaskingText(model.number), |
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 - ๊ตฌํ์ฒด๋ฅผ ๋ง๋ ๋ค, Card ์ปดํฌ๋ํธ์ ํ๋ผ๋ฏธํฐ์๋ interface๋ฅผ ๋ฐ๊ณ , ๋ํดํธ ํ๋ผ๋ฏธํฐ๋ก ๊ตฌํ์ฒด๋ฅผ ๋ฐ๋ ํํ๋ก ์์กด๊ด๊ณ๋ฅผ ๋์จํ๊ฒ ๊ตฌ์ฑํด๋ณด๋ ๊ฑด ์ด๋จ๊น์?
์๋ ํ์ธ์ ์คํ๋ ๋ฆฌ๋ทฐ ์๋ถํ๋๋ฆฝ๋๋ค :)
๊ตฌํ ์ฌํญ
๊ธฐ์กด์ ํด๋ฆญ ์ด๋ฒคํธ๋ฅผ composable ์์ ์ฒ๋ฆฌํ๋๋ฐ, viewModel ๊ณผ Activity ์์ ์ฒ๋ฆฌํ๊ฒ ๋ณ๊ฒฝํ์ต๋๋ค.
composable ์ UI ๋ฅผ ๊ทธ๋ฆฌ๊ธฐ ์ํจ์ด์ง ๋ก์ง ์ฒ๋ฆฌ๋ฅผ ํ๋ ๊ณณ์ ์๋๋ฐ, UI ๋ฅผ ๊ทธ๋ฆฌ๋ ๊ฒ๊ณผ ์๊ด ์๋, ํ ์คํธ ๋ ธ์ถ์ด๋ ๋ด๋น๊ฒ์ด์ ๋์์
Activity ์์ ์ฒ๋ฆฌํ์ต๋๋ค.
์ถ๊ฐ/์์ ์ ํ๊ฐ๋ฆํ๊ธฐ ์ํด ์ต์ด์ ๋ฐ์์จ Card ์ ๋ณด๋ฅผ ์ฒ๋ฆฌํ๋ ๋ถ๋ถ๋, rember ๋ฅผ ์ด์ฉํ์ต๋๋ค.
๋ณดํต ํ๋ก์ ํธ์์ DI ๋ฅผ ์ฌ์ฉํด์ viewModel ์ ํด๋น ๊ฐ์ Injection ํด์ ์ฌ์ฉํ์๋๋ฐ, ์ด๋ฒ์ฒ๋ผ composable ์ ์ํฅ์ ์ค ์ ์๋ ๊ณณ์ ์ฌ์ฉํ๋ค ๋ณด๋ ํด๋น ํค์๋๋ฅผ ๋ ์ ์ดํดํ๊ฒ ๋์ด ๋ฐฐ์ด์ ์ด ๋ง์ ๊ณผ์ ์์ต๋๋ค :)