Skip to content

Commit f528770

Browse files
authored
Update README.md
1 parent 59c7356 commit f528770

File tree

1 file changed

+43
-55
lines changed

1 file changed

+43
-55
lines changed

README.md

Lines changed: 43 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -36,72 +36,60 @@ Languages:
3636

3737
```kotlin
3838
@Composable
39-
fun MCodeCountryCodePicker(
40-
modifier: Modifier = Modifier,
41-
text: String,
42-
onValueChange: (String) -> Unit,
43-
shape: Shape = RoundedCornerShape(24.dp),
44-
color: Color = MaterialTheme.colors.background,
45-
showCountryCode: Boolean = true,
46-
showCountryFlag: Boolean = true,
47-
focusedBorderColor: Color = MaterialTheme.colors.primary,
48-
unfocusedBorderColor: Color = MaterialTheme.colors.onSecondary,
49-
cursorColor: Color = MaterialTheme.colors.primary,
50-
bottomStyle: Boolean = false
51-
)
39+
CountryTextField(
40+
label = stringResource(R.string.select_country_text),
41+
modifier = Modifier
42+
.padding(top = 50.dp)
43+
.align(Alignment.TopCenter),
44+
expanded = expanded,
45+
selectedCountry = selectedCountry,
46+
defaultSelectedCountry = countryList(LocalContext.current).single { it.code == "IN" }
47+
) {
48+
49+
}
5250

5351
```
5452

5553
<h3> EXAMPLE </h3>
5654

5755

5856
```kotlin
59-
60-
@Composable
61-
fun CountryCodePick() {
62-
Column(
63-
modifier = Modifier
64-
.verticalScroll(rememberScrollState())
65-
.fillMaxSize(),
66-
verticalArrangement = Arrangement.Center,
67-
horizontalAlignment = Alignment.CenterHorizontally
68-
) {
69-
70-
val phoneNumber = rememberSaveable { mutableStateOf("") }
71-
val fullPhoneNumber = rememberSaveable { mutableStateOf("") }
72-
val onlyPhoneNumber = rememberSaveable { mutableStateOf("") }
73-
74-
MCodeCountryCodePicker(
75-
text = phoneNumber.value,
76-
onValueChange = { phoneNumber.value = it },
77-
unfocusedBorderColor = MaterialTheme.colors.primary,
78-
bottomStyle =false,
79-
shape = RoundedCornerShape(24.dp)
80-
)
81-
Spacer(modifier = Modifier.height(10.dp))
82-
Button(onClick = {
83-
if (!isPhoneNumber()) {
84-
fullPhoneNumber.value = getFullPhoneNumber()
85-
onlyPhoneNumber.value = getOnlyPhoneNumber()
86-
} else {
87-
fullPhoneNumber.value = "Error"
88-
onlyPhoneNumber.value = "Error"
89-
}
57+
Box {
58+
var expanded by remember { mutableStateOf(false) }
59+
var selectedCountry by remember { mutableStateOf<Country?>(null) }
60+
val focusManager = LocalFocusManager.current
61+
62+
CountryPickerBottomSheet(title = {
63+
Text(
64+
modifier = Modifier
65+
.fillMaxWidth()
66+
.padding(16.dp),
67+
text = "Select Country", textAlign = TextAlign.Center,
68+
fontWeight = FontWeight.Bold,
69+
fontSize = 20.sp
70+
)
71+
}, expanded, onDismissRequest = {
72+
expanded = false
73+
}, onItemSelected = {
74+
selectedCountry = it
75+
expanded = false
76+
focusManager.clearFocus()
9077
}) {
91-
Text(text = "Check")
92-
}
78+
CountryTextField(
79+
label = "Select country",
80+
modifier = Modifier
81+
.padding(top = 50.dp)
82+
.align(Alignment.TopCenter),
83+
expanded,
84+
defaultSelectedCountry = countryList(LocalContext.current).single { it.code == "IN" },
85+
selectedCountry
86+
) {
87+
expanded = !expanded
88+
}
9389

94-
Text(
95-
text = "Full Phone Number: ${fullPhoneNumber.value}",
96-
color = if (getErrorStatus()) Color.Red else Color.Green
97-
)
90+
}
9891

99-
Text(
100-
text = "Only Phone Number: ${onlyPhoneNumber.value}",
101-
color = if (getErrorStatus()) Color.Red else Color.Green
102-
)
10392
}
104-
}
10593

10694
```
10795

0 commit comments

Comments
 (0)