Jetpack Compose 국가 코드 선택기
링크 : Github
하이라이트
*예시 : *
@Composable
fun SelectCountryWithCountryCode() {
val getDefaultLangCode = getDefaultLangCode() // Auto detect language
val getDefaultPhoneCode = getDefaultPhoneCode() // Auto detect phone code : +90
var phoneCode by rememberSaveable { mutableStateOf(getDefaultPhoneCode) }
val phoneNumber = rememberSaveable { mutableStateOf("") }
var defaultLang by rememberSaveable { mutableStateOf(getDefaultLangCode) }
var verifyText by remember { mutableStateOf("") }
var isValidPhone by remember { mutableStateOf(true) }
Column(
modifier = Modifier.padding(16.dp)
) {
Text(
text = verifyText,
fontWeight = FontWeight.Bold,
modifier = Modifier
.fillMaxWidth()
.wrapContentSize(Alignment.Center)
)
TogiCountryCodePicker(
pickedCountry = {
phoneCode = it.countryPhoneCode
defaultLang = it.countryCode
},
defaultCountry = getLibCountries().single { it.countryCode == defaultLang },
focusedBorderColor = MaterialTheme.colors.primary,
unfocusedBorderColor = MaterialTheme.colors.primary,
dialogAppBarTextColor = Color.Black,
dialogAppBarColor = Color.White,
error = isValidPhone,
text = phoneNumber.value,
onValueChange = { phoneNumber.value = it }
)
val fullPhoneNumber = "$phoneCode${phoneNumber.value}"
val checkPhoneNumber = checkPhoneNumber(
phone = phoneNumber.value,
fullPhoneNumber = fullPhoneNumber,
countryCode = defaultLang
)
Button(
onClick = {
verifyText = if (checkPhoneNumber) {
isValidPhone = true
"Phone Number Correct"
} else {
isValidPhone = false
"Phone Number is Wrong"
}
},
modifier = Modifier.fillMaxWidth()
.padding(16.dp)
.height(60.dp)
) {
Text(text = "Phone Verify")
}
}
}
}
Reference
이 문제에 관하여(Jetpack Compose 국가 코드 선택기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/caglayantolga/jetpack-compose-country-code-picker-4nag텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)