Skip to content

Commit 14204bb

Browse files
Merge pull request #7 from arpitkatiyar1999/v2.1.0
V2.1.0
2 parents bea4594 + b1827cb commit 14204bb

File tree

13 files changed

+512
-272
lines changed

13 files changed

+512
-272
lines changed

.idea/other.xml

+12-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CountryPicker/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ afterEvaluate {
5454
create<MavenPublication>("release") {
5555
groupId = "com.github.arpitkatiyar1999"
5656
artifactId = "countrypicker"
57-
version = "2.0.0"
57+
version = "2.1.0"
5858
from(components["release"])
5959
}
6060
}

CountryPicker/src/main/java/com/arpitkatiyarprojects/countrypicker/CountryPicker.kt

+13-7
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ import androidx.compose.runtime.remember
2020
import androidx.compose.runtime.setValue
2121
import androidx.compose.ui.Alignment
2222
import androidx.compose.ui.Modifier
23+
import androidx.compose.ui.draw.clip
2324
import androidx.compose.ui.layout.ContentScale
2425
import androidx.compose.ui.platform.LocalContext
2526
import androidx.compose.ui.res.painterResource
2627
import androidx.compose.ui.res.stringResource
2728
import androidx.compose.ui.unit.dp
29+
import com.arpitkatiyarprojects.countrypicker.enums.CountryListDisplayType
2830
import com.arpitkatiyarprojects.countrypicker.models.CountriesListDialogDisplayProperties
2931
import com.arpitkatiyarprojects.countrypicker.models.CountryDetails
3032
import com.arpitkatiyarprojects.countrypicker.models.SelectedCountryDisplayProperties
@@ -39,6 +41,7 @@ import com.arpitkatiyarprojects.countrypicker.utils.FunctionHelper
3941
* @param countriesListDialogDisplayProperties The [CountriesListDialogDisplayProperties] properties related to the country selection dialog, including flag dimensions and text styles.
4042
* @param defaultCountryCode Specifies the default country code to be pre-selected in the picker. The code must adhere to the 2-letter ISO standard. For example, "in" represents India. If not explicitly provided, the picker will automatically detect the user's country.
4143
* @param countriesList Specifies a list of countries to populate in the picker. If not provided, the picker will use a predefined list of countries. It's essential that the provided countries list strictly adheres to the standard 2-letter ISO code format for each country.
44+
* @param countryListDisplayType The type of UI to use for displaying the list (BottomSheet or Dialog).
4245
* @param onCountrySelected The callback function is triggered each time a country is selected within the picker. Additionally, it is also invoked when the picker is first displayed on the screen with the default selected country.
4346
*/
4447
@Composable
@@ -49,10 +52,11 @@ fun CountryPicker(
4952
countriesListDialogDisplayProperties: CountriesListDialogDisplayProperties = CountriesListDialogDisplayProperties(),
5053
defaultCountryCode: String? = null,
5154
countriesList: List<String>? = null,
55+
countryListDisplayType: CountryListDisplayType = CountryListDisplayType.Dialog,
5256
onCountrySelected: (country: CountryDetails) -> Unit
5357
) {
5458
val context = LocalContext.current
55-
var openCountrySelectionDialog by remember { mutableStateOf(false) }
59+
var openCountrySelectionList by remember { mutableStateOf(false) }
5660
val applicableCountriesList = remember {
5761
val allCountriesList = FunctionHelper.getAllCountries(context)
5862
if (countriesList.isNullOrEmpty()) {
@@ -73,16 +77,17 @@ fun CountryPicker(
7377
}
7478
)
7579
}
76-
if (openCountrySelectionDialog) {
77-
CountrySelectionDialog(
80+
if (openCountrySelectionList) {
81+
CountrySelectionList(
7882
countriesList = applicableCountriesList,
7983
countriesListDialogDisplayProperties = countriesListDialogDisplayProperties,
84+
countryListDisplayType = countryListDisplayType,
8085
onDismissRequest = {
81-
openCountrySelectionDialog = false
86+
openCountrySelectionList = false
8287
},
8388
onSelected = { country ->
8489
selectedCountry = country
85-
openCountrySelectionDialog = false
90+
openCountrySelectionList = false
8691
onCountrySelected(country)
8792
},
8893
)
@@ -93,7 +98,7 @@ fun CountryPicker(
9398
selectedCountryDisplayProperties = selectedCountryDisplayProperties,
9499
modifier = modifier
95100
) {
96-
openCountrySelectionDialog = !openCountrySelectionDialog
101+
openCountrySelectionList = !openCountrySelectionList
97102
}
98103
}
99104

@@ -129,7 +134,8 @@ private fun SelectedCountrySection(
129134
Image(
130135
modifier = Modifier
131136
.width(flagDimensions.width)
132-
.height(flagDimensions.height),
137+
.height(flagDimensions.height)
138+
.clip(flagShape),
133139
painter = painterResource(selectedCountry.countryFlag),
134140
contentScale = ContentScale.Crop,
135141
contentDescription = selectedCountry.countryName

CountryPicker/src/main/java/com/arpitkatiyarprojects/countrypicker/CountryPickerOutlinedTextField.kt

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import androidx.compose.ui.text.input.ImeAction
1919
import androidx.compose.ui.text.input.KeyboardType
2020
import androidx.compose.ui.text.input.VisualTransformation
2121
import androidx.compose.ui.unit.dp
22+
import com.arpitkatiyarprojects.countrypicker.enums.CountryListDisplayType
2223
import com.arpitkatiyarprojects.countrypicker.models.BorderThickness
2324
import com.arpitkatiyarprojects.countrypicker.models.CountriesListDialogDisplayProperties
2425
import com.arpitkatiyarprojects.countrypicker.models.CountryDetails
@@ -52,6 +53,7 @@ import com.arpitkatiyarprojects.countrypicker.models.SelectedCountryDisplayPrope
5253
* @param shape defines the shape of this text field's border.
5354
* @param colors [TextFieldColors] that will be used to resolve the colors used for this text field in different.
5455
* @param borderThickness Represents the border thickness for focused and unfocused states.
56+
* @param countryListDisplayType The type of UI to use for displaying the list (BottomSheet or Dialog).
5557
* @param onDone The callback is triggered when the user clicks the Done button on the keyboard, as the default IME action is set to Done.
5658
*/
5759
@Composable
@@ -83,6 +85,7 @@ fun CountryPickerOutlinedTextField(
8385
shape: Shape = RoundedCornerShape(12.dp),
8486
colors: TextFieldColors = OutlinedTextFieldDefaults.colors(),
8587
borderThickness: BorderThickness = BorderThickness(),
88+
countryListDisplayType: CountryListDisplayType = CountryListDisplayType.Dialog,
8689
onDone: (() -> Unit)? = null,
8790
) {
8891
PickerOutlinedTextField(
@@ -104,6 +107,7 @@ fun CountryPickerOutlinedTextField(
104107
countriesListDialogDisplayProperties = countriesListDialogDisplayProperties,
105108
defaultCountryCode = defaultCountryCode,
106109
countriesList = countriesList,
110+
countryListDisplayType = countryListDisplayType,
107111
onCountrySelected = onCountrySelected
108112
)
109113
},

0 commit comments

Comments
 (0)