KomposeCountryCodePicker

fun KomposeCountryCodePicker(state: CountryCodePicker, text: String, modifier: Modifier = Modifier, onValueChange: (String) -> Unit = {}, error: Boolean = false, showOnlyCountryCodePicker: Boolean = false, shape: Shape = MaterialTheme.shapes.medium, placeholder: @Composable (defaultLang: String) -> Unit = { defaultLang -> DefaultPlaceholder(defaultLang) }, colors: TextFieldColors = TextFieldDefaults.colors(), trailingIcon: @Composable () -> Unit? = null, countrySelectionDialogContainerColor: Color = MaterialTheme.colorScheme.background, countrySelectionDialogContentColor: Color = MaterialTheme.colorScheme.onBackground, countrySelectionDialogTitle: @Composable () -> Unit = { Text( modifier = Modifier .offset(y = (-2).dp) .qaAutomationTestTag("countryDialogTitle"), text = stringResource(Res.string.select_country), style = MaterialTheme.typography.titleMedium, color = countrySelectionDialogContentColor, ) }, countrySelectionDialogBackIcon: @Composable () -> Unit = { Icon( painter = painterResource(Res.drawable.ic_arrow_back), contentDescription = "Back", tint = countrySelectionDialogContentColor, ) }, countrySelectionDialogSearchIcon: @Composable () -> Unit = { Icon( painter = painterResource(Res.drawable.ic_search), contentDescription = "Search", tint = countrySelectionDialogContentColor, ) }, interactionSource: MutableInteractionSource = MutableInteractionSource(), selectedCountryFlagSize: FlagSize = FlagSize(28.dp, 18.dp), textStyle: TextStyle = LocalTextStyle.current, enabled: Boolean = true, keyboardOptions: KeyboardOptions = KeyboardOptions.Default.copy( keyboardType = KeyboardType.Phone, imeAction = ImeAction.Next, ), keyboardActions: KeyboardActions = KeyboardActions.Default)

KomposeCountryCodePicker is a composable that displays a text field with a country code picker dialog.

All lambda parameters (onValueChange, placeholder, trailingIcon, countrySelectionDialogTitle, countrySelectionDialogBackIcon, countrySelectionDialogSearchIcon) are invoked synchronously on the main thread during composition. Exceptions thrown inside these lambdas will propagate to the caller and may crash the composition — callers should handle their own errors.

Parameters

state

The state of the country code picker.

text

The text to be displayed in the text field.

modifier

Modifier to be applied to the layout.

onValueChange

Called on the main thread when the text field value changes. The new value is passed as a parameter. Exceptions thrown in this lambda will propagate to the caller.

error

If true, the text field will be displayed in the error state.

showOnlyCountryCodePicker

If true, only the country code picker will be displayed without the text field.

shape

The shape of the text field's outline.

placeholder

A composable lambda invoked during composition to display the placeholder in the text field. Receives the current country code as a parameter.

colors

The colors to be used to display the text field.

trailingIcon

The trailing icon to be displayed in the text field.

countrySelectionDialogContainerColor

The color of the country selection dialog container.

countrySelectionDialogContentColor

The color of the country selection dialog content.

countrySelectionDialogTitle

A composable lambda to display the title of the country selection dialog.

countrySelectionDialogBackIcon

A composable lambda to display the back icon in the country selection dialog.

countrySelectionDialogSearchIcon

A composable lambda to display the search icon in the country selection dialog.

interactionSource

The MutableInteractionSource representing the stream of Interactions for this text field.

selectedCountryFlagSize

The size of the selected country flag (width and height in androidx.compose.ui.unit.Dp).

textStyle

The style to be used for displaying text on the TextField and the selected country.

enabled

Controls the enabled state of the text field.

keyboardOptions

The keyboard options to be used for the text field.

keyboardActions

The keyboard actions to be used for the text field.