If you need to use your own design system, you can bypass the default KomposeCountryCodePicker component. Instead, use CountrySelectionDialog to show the picker and interact with state.selectedCountry and state.countryList to drive your custom UI. Use state.setCode(country.code) to update the selection.
@OptIn(RestrictedApi::class)
@Composable
fun PhoneNumberField() {
var phoneNumber by rememberSaveable { mutableStateOf("") }
var showCountryPicker by rememberSaveable { mutableStateOf(false) }
val state = rememberKomposeCountryCodePickerState()
if (showCountryPicker) {
CountrySelectionDialog(
countryList = state.countryList,
containerColor = MaterialTheme.colorScheme.background,
contentColor = MaterialTheme.colorScheme.onBackground,
onDismissRequest = { showCountryPicker = false },
onSelect = { country ->
state.setCode(country.code)
showCountryPicker = false
},
)
}
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
value = phoneNumber,
onValueChange = { phoneNumber = it },
placeholder = { Text("Phone Number") },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Phone),
leadingIcon = {
Row(
modifier = Modifier
.clickable { showCountryPicker = true }
.padding(start = 12.dp, end = 8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Image(
modifier = Modifier.width(28.dp).height(18.dp),
painter = painterResource(state.selectedCountry.flag),
contentDescription = state.selectedCountry.name,
)
Spacer(modifier = Modifier.width(6.dp))
Text(text = state.selectedCountry.phoneNoCode)
}
},
)
}