Skip to content

Commit

Permalink
Fixes some Dutch and French translations, use ellipses, sort by strin…
Browse files Browse the repository at this point in the history
…g key (#44)

* Sort strings by key in all languages, fix some dutch

* French fixes

* fixes error logging

* update docs and version number

* unicode ellipses

* clean up example code
  • Loading branch information
hbmartin authored Oct 11, 2023
1 parent 39a540e commit 458226b
Show file tree
Hide file tree
Showing 15 changed files with 1,319 additions and 1,314 deletions.
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,37 @@ See [MainActivity in the sample app](https://github.com/jump-sdk/jetpack_compose
Also check out the [ComposeCountryCodePicker documentation](https://jump-sdk.github.io/jetpack_compose_country_code_picker_emoji/ccp/com.togitech.ccp.component/-togi-country-code-picker.html) for all available composables and utilities.

```kotlin
var phoneNumber = rememberSaveable { mutableStateOf("") }
var fullPhoneNumber = rememberSaveable { mutableStateOf("") }
var isNumberValid: Boolean by rememberSaveable { mutableStateOf(false) }

TogiCountryCodePicker(
onValueChange = { (code, phone), isValid ->
Log.d("CCP", "onValueChange: $code $phone -> $isValid")

phoneNumber.value = phone
fullPhoneNumber.value = code + phone
isNumberValid = isValid
},
)
var phoneNumber by rememberSaveable { mutableStateOf("") }
var fullPhoneNumber by rememberSaveable { mutableStateOf("") }
var isNumberValid: Boolean by rememberSaveable { mutableStateOf(false) }

TogiCountryCodePicker(
modifier = Modifier.fillMaxWidth().padding(horizontal = 10.dp),
onValueChange = { (code, phone), isValid ->
Log.d("CCP", "onValueChange: $code $phone -> $isValid")

phoneNumber = phone
fullPhoneNumber = code + phone
isNumberValid = isValid
},
label = { Text("Phone Number") },
)
```


| Parameter | Description |
|-------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| onValueChange | Called when the text in the text field changes. The first parameter is string pair of (country code, phone number) and the second parameter is a boolean indicating whether the phone number is valid. |
| onValueChange | Called when the text in the text field changes. The first parameter is string pair of (country phone code, phone number) and the second parameter is a boolean indicating whether the phone number is valid. |
| modifier | Modifier to be applied to the inner OutlinedTextField. |
| enabled | Boolean indicating whether the field is enabled. |
| shape | Shape of the text field. |
| showCountryCode | Whether to show the country code in the text field. |
| showCountryFlag | Whether to show the country flag in the text field. |
| colors | Colors to be used for the text field. Defaults to [outlinedTextFieldColors](https://developer.android.com/reference/kotlin/androidx/compose/material/TextFieldDefaults) |
| colors | TextFieldColors to be used for the text field. Defaults to [outlinedTextFieldColors](https://developer.android.com/reference/kotlin/androidx/compose/material/TextFieldDefaults) |
| fallbackCountry | The country to be used as a fallback if the user's country cannot be determined. Defaults to the United States. See [CountryData](https://jump-sdk.github.io/jetpack_compose_country_code_picker_emoji/ccp/com.togitech.ccp.data/-country-data/index.html) |
| showPlaceholder | Whether to show the placeholder number in the text field. |
| showPlaceholder | Whether to show the placeholder number hint in the text field. |
| includeOnly | A set of 2 digit country codes to be included in the list of countries. Set to null to include all supported countries. |
| clearIcon | The icon to be used for the clear button. Set to null to disable the clear button. |
| clearIcon | ImageVector to be used for the clear button. Set to null to disable the clear button. Defaults to Icons.Filled.Clear |
| initialPhoneNumber | An optional phone number to be initial value of the input field. |
| initialCountryIsoCode | Optional ISO-3166-1 alpha-2 country code to set the initially selected country. Note that if a valid initialCountryPhoneCode is provided, this will be ignored. |
| initialCountryPhoneCode | Optional country phone code to set the initially selected country. This takes precedence over initialCountryIsoCode. |
Expand Down Expand Up @@ -96,7 +98,7 @@ Step 2. Add the dependency
```kotlin
dependencies {
implementation("androidx.compose.material:material:1.5.3")
implementation("com.github.jump-sdk:jetpack_compose_country_code_picker_emoji:2.2.1")
implementation("com.github.jump-sdk:jetpack_compose_country_code_picker_emoji:2.2.3")
}
```

Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/com/togitech/togii/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ fun CountryCodePick() {
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
) {
val phoneNumber = rememberSaveable { mutableStateOf("") }
val fullPhoneNumber = rememberSaveable { mutableStateOf("") }
var phoneNumber by rememberSaveable { mutableStateOf("") }
var fullPhoneNumber by rememberSaveable { mutableStateOf("") }
var isNumberValid: Boolean by rememberSaveable { mutableStateOf(false) }

Spacer(modifier = Modifier.height(100.dp))
Expand All @@ -78,21 +78,21 @@ fun CountryCodePick() {
modifier = Modifier.fillMaxWidth().padding(horizontal = 10.dp),
onValueChange = { (code, phone), isValid ->
Log.d("CCP", "onValueChange: $code $phone -> $isValid")
phoneNumber.value = phone
fullPhoneNumber.value = code + phone
phoneNumber = phone
fullPhoneNumber = code + phone
isNumberValid = isValid
},
label = { Text("Test Label") },
label = { Text("Phone Number") },
)
Spacer(modifier = Modifier.height(10.dp))

Text(
text = "Full Phone Number: ${fullPhoneNumber.value}",
text = "Full Phone Number: $fullPhoneNumber",
color = if (!isNumberValid) Color.Red else Color.Green,
)

Text(
text = "Only Phone Number: ${phoneNumber.value}",
text = "Only Phone Number: $phoneNumber",
color = if (!isNumberValid) Color.Red else Color.Green,
)
Spacer(modifier = Modifier.weight(1f))
Expand Down
2 changes: 1 addition & 1 deletion ccp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ afterEvaluate {
groupId = "com.togisoft"
artifactId = "jetpack_country_code_picker"
// Update version in README when changing below
version = "2.2.1"
version = "2.2.3"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,21 @@ private const val TAG = "TogiCountryCodePicker"

/**
* @param onValueChange Called when the text in the text field changes.
* The first parameter is string pair of (country code, phone number) and the second parameter is
* The first parameter is string pair of (country phone code, phone number) and the second parameter is
* a boolean indicating whether the phone number is valid.
* @param modifier Modifier to be applied to the inner OutlinedTextField.
* @param enabled Boolean indicating whether the field is enabled.
* @param shape Shape of the text field.
* @param showCountryCode Whether to show the country code in the text field.
* @param showCountryFlag Whether to show the country flag in the text field.
* @param colors Colors to be used for the text field.
* @param colors TextFieldColors to be used for the text field.
* @param fallbackCountry The country to be used as a fallback if the user's country cannot be determined.
* Defaults to the United States.
* @param showPlaceholder Whether to show the placeholder number in the text field.
* @param showPlaceholder Whether to show the placeholder number hint in the text field.
* @param includeOnly A set of 2 digit country codes to be included in the list of countries.
* Set to null to include all supported countries.
* @param clearIcon The icon to be used for the clear button. Set to null to disable the clear button.
* @param clearIcon ImageVector to be used for the clear button. Set to null to disable the clear button.
* Defaults to Icons.Filled.Clear
* @param initialPhoneNumber an optional phone number to be initial value of the input field
* @param initialCountryIsoCode Optional ISO-3166-1 alpha-2 country code to set the initially selected country.
* Note that if a valid initialCountryPhoneCode is provided, this will be ignored.
Expand Down Expand Up @@ -105,7 +106,9 @@ fun TogiCountryCodePicker(
initialCountryIsoCode: Iso31661alpha2? = null,
initialCountryPhoneCode: PhoneCode? = null,
label: @Composable (() -> Unit)? = null,
textStyle: TextStyle = MaterialTheme.typography.body1.copy(color = MaterialTheme.colors.onSurface),
textStyle: TextStyle = MaterialTheme.typography.body1.copy(
color = MaterialTheme.colors.onSurface,
),
) {
val context = LocalContext.current
val focusRequester = remember { FocusRequester() }
Expand Down Expand Up @@ -181,10 +184,11 @@ fun TogiCountryCodePicker(
)
onValueChange(country.countryPhoneCode to phoneNumber.text, isNumberValid)
keyboardController?.hide()
// https://github.com/jump-sdk/jetpack_compose_country_code_picker_emoji/issues/42
try {
focusRequester.freeFocus()
} catch (exception: IllegalStateException) {
Log.e(TAG, "Unable to free focus ${exception.stackTrace}")
Log.e(TAG, "Unable to free focus", exception)
}
},
focusRequester = focusRequester,
Expand Down
Loading

0 comments on commit 458226b

Please sign in to comment.