Country code bottom sheet picker in Jetpack Compose with Search functionality.
Available on Maven Central.
Add the dependency
implementation 'com.canopas.jetcountrypicker:jetcountrypicker:1.0.9'
var openBottomSheet by rememberSaveable { mutableStateOf(false) }
var selectedCountry by remember { mutableStateOf<Country?>(null) }
Box {
CountryTextField(
label = stringResource(R.string.select_country_text),
modifier = Modifier
.fillMaxWidth()
.padding(top = 50.dp, start = 40.dp, end = 40.dp),
selectedCountry = selectedCountry,
defaultCountry = countryList(LocalContext.current).firstOrNull { it.code == "IN" },
onShowCountryPicker = {
openBottomSheet = true
}, isPickerVisible = openBottomSheet
)
}
if (openBottomSheet) {
CountryPickerBottomSheet(
bottomSheetTitle = {
Text(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
text = stringResource(R.string.select_country_text),
textAlign = TextAlign.Center,
fontWeight = FontWeight.Bold,
fontSize = 20.sp
)
},
containerColor = Color.White,
onItemSelected = {
selectedCountry = it
openBottomSheet = false
}, onDismissRequest = {
openBottomSheet = false
}
)
}
Sample app demonstrates how simple the usage of the library actually is.
For bugs, questions and discussions please use the Github Issues.
JetCountryPicker is owned and maintained by the Canopas team. You can follow them on Twitter at @canopassoftware for project updates and releases.
Copyright 2022 Canopas Software LLP
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.