Skip to content

Instantly share code, notes, and snippets.

@MohitGupta121
Created October 8, 2022 11:28
Show Gist options
  • Save MohitGupta121/6ece10630a5f90220b122d483a3de34e to your computer and use it in GitHub Desktop.
Save MohitGupta121/6ece10630a5f90220b122d483a3de34e to your computer and use it in GitHub Desktop.
@Composable
fun CountryPickerSheet() {
Box {
var expanded by remember { mutableStateOf(false) }
var selectedCountry by remember { mutableStateOf<Country?>(null) }
val focusManager = LocalFocusManager.current
CountryPickerBottomSheet(
title = {
Text(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
text = stringResource(R.string.select_country_text),
textAlign = TextAlign.Center,
fontWeight = FontWeight.Bold,
fontSize = 20.sp
)
},
expanded,
onDismissRequest = {
expanded = false
},
onItemSelected = {
selectedCountry = it
expanded = false
focusManager.clearFocus()
}
) {
CountryTextField(
label = stringResource(R.string.select_country_text),
modifier = Modifier
.padding(top = 50.dp)
.align(Alignment.TopCenter),
expanded = expanded,
selectedCountry = selectedCountry,
defaultSelectedCountry = countryList(LocalContext.current).single { it.code == "IN" }
) {
expanded = !expanded
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment