๐๋์๋ ๋งํ ์ง๋ ๋ธ๋ก๊ทธ ํฌ์คํ
MutableState
์ ์ธ ๋ฐฉ์์ ๋ฐ๋ผ ๋์์ ์ฐจ์ด๊ฐ ์๋ ๊ฒ์ ๋ฐ๊ฒฌํ๋ค!isNotBlank
)์๋ง ํด๋๋ฅผ ์ถ๊ฐํ๋ ๋ฒํผ ์ํ
๊ฐ enable ๋๋๋ก ์
๋ ฅ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ๊ตฌํํ๊ณ ์ ํจMutableState
์ธ folderName ์ ์ธderivedStateOf
side-effect๋ฅผ ์ด์ฉํด ์ ์ธ@Composable
fun AddFolderDialog(
modifier: Modifier = Modifier,
onDismissRequest: () -> Unit,
addFolder: (String, String) -> Unit
) {
// delegates
var folderName by remember { mutableStateOf("") }
val setFolderName = {it:String -> folderName = it}
// destructing declarations
//val (folderName, setFolderName) = remember { mutableStateOf("") }
val (folderColorHex, setFolderColorHex) = remember { mutableStateOf(FolderColor.COLOR1.colorHex) }
val nameValid by remember { derivedStateOf { folderName.isNotBlank() } }
Dialog(
onDismissRequest = onDismissRequest,
) {
Card(
modifier = modifier.height(IntrinsicSize.Min),
shape = RoundedCornerShape(16.dp)
) {
Column(
modifier = modifier.padding(16.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
// Dialog title
Text(
modifier = modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
text = stringResource(R.string.add_folder_title),
)
// ํด๋ ์ด๋ฆ์ ์
๋ ฅ๋ฐ๋ Composable
// ํด๋ ์ด๋ฆ ์
๋ ฅ ๊ฐ = folderName
FolderNameInput(
modifier = modifier.padding(top = 16.dp),
value = folderName,
onValueChange = setFolderName
)
// ํด๋ ์์์ ์
๋ ฅ๋ฐ๋ Composable
FolderColorSelect(
modifier = modifier.padding(top = 16.dp),
colorHexes = FolderColor.entries.map { it.colorHex }.drop(1),
selectedColorHex = folderColorHex,
onColorSelect = setFolderColorHex
)
// Dialog dismiss ๋ฒํผ/confirm ๋ฒํผ Composable
// confirm ๋ฒํผ enabel ์ฌ๋ถ = nameValid
DialogButtons(
modifier = modifier.padding(top = 16.dp),
dismissButtonLabelId = R.string.add_folder_negative,
onDismissRequest = onDismissRequest,
confirmButtonLabelId = R.string.add_folder_positive,
enableConfirmButton = nameValid,
onConfirmRequest = { addFolder(folderName, folderColorHex) }
)
}
}
}
}
๐์ฐธ๊ณ ์๋ฃ
MutableState
์ write์ ํ๋ ๊ฒฝ์ฐ, state์ snapshot์ ์ํฅ์ ์คMutableState
์ ์ ์ธํ์ฌ state์ ๊ฐ์ ์ฝ๋ ๊ฒฝ์ฐMutableState.value
operation์ delegateMutableState
์ ์ ์ธํ์ฌ state์ ๊ฐ์ ์ฝ๋ ๊ฒฝ์ฐMutableState.value
operation ๋ถ๋ฆฌ์ง X, component1์ ์ค์ ํ ๋ ํ ๋ฒ๋ง ๋ถ๋ฆผ