zfan93
10/12/2023, 7:23 AMJan
10/12/2023, 7:28 AMzfan93
10/12/2023, 8:04 AMElijah Semyonov
10/12/2023, 8:31 AMAlexander Maryanovsky
10/12/2023, 8:54 AMzfan93
10/12/2023, 11:39 AMclass PhoneScreenModel(private val navigator: Navigator) : MyViewModel() {
val phone = MutableStateFlow("")
fun updatePhone(newPhone: String) {
if (newPhone.length <= 11 && newPhone.all { it.isDigit() }) {
phone.value = newPhone
}
}
the textfield:
TextField(
modifier = Modifier.fillMaxWidth().padding(bottom = 16.dp).border(
1.dp,
color = MaterialTheme.colorScheme.primary,
shape = RoundedCornerShape(8.dp)
),
value = phone,
onValueChange = { newPhone ->
if (newPhone.length <= 11 && newPhone.all { it.isDigit() } && (newPhone.startsWith(
"1"
) || newPhone.isEmpty())) {
phoneScreenModel.updatePhone(newPhone)
if (newPhone.length == 11) {
keyboardController?.hide()
navigator.push(CodeScreen(newPhone))
}
}
}, colors = TextFieldDefaults.colors(
unfocusedContainerColor = MaterialTheme.colorScheme.background,
focusedContainerColor = MaterialTheme.colorScheme.background,
unfocusedIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent,
focusedTextColor = MaterialTheme.colorScheme.primary,
unfocusedTextColor = MaterialTheme.colorScheme.primary,
),
shape = RoundedCornerShape(8.dp),
placeholder = {
Box(
modifier = Modifier.fillMaxWidth().height(26.dp),
contentAlignment = Alignment.Center
) {
Text(
text = "请输入手机号",
color = MaterialTheme.colorScheme.primary
)
}
},
textStyle = TextStyle(textAlign = TextAlign.Center, fontSize = 20.sp),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number)
)
Alexander Zhirkevich
10/12/2023, 11:47 AMAlexander Maryanovsky
10/12/2023, 11:48 AMzfan93
10/12/2023, 11:52 AMAlexander Zhirkevich
10/12/2023, 11:56 AMElijah Semyonov
10/12/2023, 11:56 AMzfan93
10/13/2023, 12:57 AMArkadii Ivanov
10/13/2023, 4:12 PM