Kompose Country Code Picker is a Jetpack Compose library based on Material 3 (M3) that provides a country code picker for Android apps.
Picker | Dialog |
---|---|
Jetpack compose material three dependency - implementation("androidx.compose.material3:material3:1.1.1")
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
Add the following to your build.gradle
dependencies:
dependencies {
implementation("com.github.JoelKanyi:KomposeCountryCodePicker:<version>")
}
val phoneNumber = rememberSaveable { mutableStateOf("") }
KomposeCountryCodePicker(
modifier = Modifier
.fillMaxWidth(),
text = phoneNumber.value,
onValueChange = { phoneNumber.value = it },
placeholder = { Text(text = "Phone Number") },
shape = MaterialTheme.shapes.medium,
colors = TextFieldDefaults.colors(
unfocusedContainerColor = Color.Transparent,
focusedContainerColor = Color.Transparent,
),
)
Customization | Description |
---|---|
limitedCountries |
Limits the list of countries to be displayed in the country code picker by specify the country codes, country names or country phone codes |
placeholder |
Sets the placeholder Composable for the country code picker |
shape |
Sets the shape of the country code picker TextField |
showCountryCode |
Shows the country code in the country code picker TextField |
showCountryFlag |
Shows the country flag in the country code picker TextField |
error |
Sets the error state on the TextField for the country code picker |
colors |
Sets the colors for the country code picker TextField |
Description | Method |
---|---|
Country Phone No Code | CountryCodePicker.getCountryPhoneCodeWithoutPrefix() |
Prefixed Country Phone No Code | CountryCodePicker.getCountryPhoneCode() |
Country Name | CountryCodePicker.getCountryName() |
Country Language Code | CountryCodePicker.getCountryCodeWithoutPrefix() |
Phone Number | CountryCodePicker.getPhoneNumber() |
Phone Number Without Prefix | CountryCodePicker.getPhoneNumberWithoutPrefix() |
Full Phone Number | CountryCodePicker.getFullPhoneNumber() |
Full Phone Number Without Prefix | CountryCodePicker.getFullPhoneNumberWithoutPrefix() |
Phone Number State | CountryCodePicker.isPhoneNumberValid() |
Please fork this repository and contribute back using pull requests.
Any contributions, large or small, major features, bug fixes, are welcomed and appreciated but will be thoroughly reviewed.
Copyright 2023 Joel Kanyi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.