Skip to content

Commit

Permalink
Merge pull request #7 from arpitkatiyar1999/v2.1.0
Browse files Browse the repository at this point in the history
V2.1.0
  • Loading branch information
arpitkatiyar1999 authored Dec 26, 2024
2 parents bea4594 + b1827cb commit 14204bb
Show file tree
Hide file tree
Showing 13 changed files with 512 additions and 272 deletions.
13 changes: 12 additions & 1 deletion .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion CountryPicker/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ afterEvaluate {
create<MavenPublication>("release") {
groupId = "com.github.arpitkatiyar1999"
artifactId = "countrypicker"
version = "2.0.0"
version = "2.1.0"
from(components["release"])
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.arpitkatiyarprojects.countrypicker.enums.CountryListDisplayType
import com.arpitkatiyarprojects.countrypicker.models.CountriesListDialogDisplayProperties
import com.arpitkatiyarprojects.countrypicker.models.CountryDetails
import com.arpitkatiyarprojects.countrypicker.models.SelectedCountryDisplayProperties
Expand All @@ -39,6 +41,7 @@ import com.arpitkatiyarprojects.countrypicker.utils.FunctionHelper
* @param countriesListDialogDisplayProperties The [CountriesListDialogDisplayProperties] properties related to the country selection dialog, including flag dimensions and text styles.
* @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.
* @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.
* @param countryListDisplayType The type of UI to use for displaying the list (BottomSheet or Dialog).
* @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.
*/
@Composable
Expand All @@ -49,10 +52,11 @@ fun CountryPicker(
countriesListDialogDisplayProperties: CountriesListDialogDisplayProperties = CountriesListDialogDisplayProperties(),
defaultCountryCode: String? = null,
countriesList: List<String>? = null,
countryListDisplayType: CountryListDisplayType = CountryListDisplayType.Dialog,
onCountrySelected: (country: CountryDetails) -> Unit
) {
val context = LocalContext.current
var openCountrySelectionDialog by remember { mutableStateOf(false) }
var openCountrySelectionList by remember { mutableStateOf(false) }
val applicableCountriesList = remember {
val allCountriesList = FunctionHelper.getAllCountries(context)
if (countriesList.isNullOrEmpty()) {
Expand All @@ -73,16 +77,17 @@ fun CountryPicker(
}
)
}
if (openCountrySelectionDialog) {
CountrySelectionDialog(
if (openCountrySelectionList) {
CountrySelectionList(
countriesList = applicableCountriesList,
countriesListDialogDisplayProperties = countriesListDialogDisplayProperties,
countryListDisplayType = countryListDisplayType,
onDismissRequest = {
openCountrySelectionDialog = false
openCountrySelectionList = false
},
onSelected = { country ->
selectedCountry = country
openCountrySelectionDialog = false
openCountrySelectionList = false
onCountrySelected(country)
},
)
Expand All @@ -93,7 +98,7 @@ fun CountryPicker(
selectedCountryDisplayProperties = selectedCountryDisplayProperties,
modifier = modifier
) {
openCountrySelectionDialog = !openCountrySelectionDialog
openCountrySelectionList = !openCountrySelectionList
}
}

Expand Down Expand Up @@ -129,7 +134,8 @@ private fun SelectedCountrySection(
Image(
modifier = Modifier
.width(flagDimensions.width)
.height(flagDimensions.height),
.height(flagDimensions.height)
.clip(flagShape),
painter = painterResource(selectedCountry.countryFlag),
contentScale = ContentScale.Crop,
contentDescription = selectedCountry.countryName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp
import com.arpitkatiyarprojects.countrypicker.enums.CountryListDisplayType
import com.arpitkatiyarprojects.countrypicker.models.BorderThickness
import com.arpitkatiyarprojects.countrypicker.models.CountriesListDialogDisplayProperties
import com.arpitkatiyarprojects.countrypicker.models.CountryDetails
Expand Down Expand Up @@ -52,6 +53,7 @@ import com.arpitkatiyarprojects.countrypicker.models.SelectedCountryDisplayPrope
* @param shape defines the shape of this text field's border.
* @param colors [TextFieldColors] that will be used to resolve the colors used for this text field in different.
* @param borderThickness Represents the border thickness for focused and unfocused states.
* @param countryListDisplayType The type of UI to use for displaying the list (BottomSheet or Dialog).
* @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.
*/
@Composable
Expand Down Expand Up @@ -83,6 +85,7 @@ fun CountryPickerOutlinedTextField(
shape: Shape = RoundedCornerShape(12.dp),
colors: TextFieldColors = OutlinedTextFieldDefaults.colors(),
borderThickness: BorderThickness = BorderThickness(),
countryListDisplayType: CountryListDisplayType = CountryListDisplayType.Dialog,
onDone: (() -> Unit)? = null,
) {
PickerOutlinedTextField(
Expand All @@ -104,6 +107,7 @@ fun CountryPickerOutlinedTextField(
countriesListDialogDisplayProperties = countriesListDialogDisplayProperties,
defaultCountryCode = defaultCountryCode,
countriesList = countriesList,
countryListDisplayType = countryListDisplayType,
onCountrySelected = onCountrySelected
)
},
Expand Down
Loading

0 comments on commit 14204bb

Please sign in to comment.