@@ -36,72 +36,60 @@ Languages:
36
36
37
37
``` kotlin
38
38
@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
+ }
52
50
53
51
```
54
52
55
53
<h3 > EXAMPLE </h3 >
56
54
57
55
58
56
``` 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()
90
77
}) {
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
+ }
93
89
94
- Text (
95
- text = " Full Phone Number: ${fullPhoneNumber.value} " ,
96
- color = if (getErrorStatus()) Color .Red else Color .Green
97
- )
90
+ }
98
91
99
- Text (
100
- text = " Only Phone Number: ${onlyPhoneNumber.value} " ,
101
- color = if (getErrorStatus()) Color .Red else Color .Green
102
- )
103
92
}
104
- }
105
93
106
94
```
107
95
0 commit comments