diff --git a/.gitignore b/.gitignore index 38ae652..c37fa82 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,9 @@ /.idea/navEditor.xml /.idea/assetWizardSettings.xml /.idea/jarRepositories.xml +/.idea/deploymentTargetDropDown.xml +/.idea/apollo.xml +/.idea/graphql-settings.xml .DS_Store /build /captures diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml deleted file mode 100644 index 0c0c338..0000000 --- a/.idea/deploymentTargetDropDown.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index 26e8e05..971e30f 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ Also check out the [ComposeCountryCodePicker documentation](https://jump-sdk.git | 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. | | label | An optional composable to be used as a label for input field. | -| textStyle | An optional [TextStyle](https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextStyle) for customizing text style of phone number input field. | +| textStyle | An optional [TextStyle](https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextStyle) for customizing text style of phone number input field. Defaults to MaterialTheme.typography.body1 | diff --git a/ccp/src/main/java/com/togitech/ccp/component/CountryDialog.kt b/ccp/src/main/java/com/togitech/ccp/component/CountryDialog.kt index 5ec1b70..6205046 100644 --- a/ccp/src/main/java/com/togitech/ccp/component/CountryDialog.kt +++ b/ccp/src/main/java/com/togitech/ccp/component/CountryDialog.kt @@ -120,19 +120,17 @@ fun CountryDialog( modifier = Modifier.padding(horizontal = SEARCH_ICON_PADDING), ) }, - modifier = Modifier.padding(DEFAULT_ROW_PADDING), ) Spacer(modifier = Modifier.height(DEFAULT_ROW_PADDING)) - Divider() LazyColumn { items(filteredCountries, key = { it.countryIso }) { countryItem -> + Divider() CountryRowItem( rowPadding = rowPadding, onSelect = { onSelect(countryItem) }, countryItem = countryItem, textStyle = textStyle, ) - Divider() } } } @@ -205,7 +203,6 @@ private fun SearchTextField( value: String, onValueChange: (String) -> Unit, textStyle: TextStyle, - modifier: Modifier = Modifier, leadingIcon: (@Composable () -> Unit)? = null, hint: String = stringResource(id = R.string.search), ) { @@ -216,7 +213,8 @@ private fun SearchTextField( } BasicTextField( - modifier = modifier + modifier = Modifier + .padding(horizontal = DEFAULT_ROW_PADDING) .height(MIN_TAP_DIMENSION) .fillMaxWidth() .focusRequester(requester), @@ -227,12 +225,10 @@ private fun SearchTextField( textStyle = textStyle, decorationBox = { innerTextField -> Row( - Modifier - .fillMaxWidth() - .height(MIN_TAP_DIMENSION), + modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, ) { - if (leadingIcon != null) leadingIcon() + leadingIcon?.invoke() Box( modifier = Modifier .padding(start = DEFAULT_ROUNDING) diff --git a/ccp/src/main/java/com/togitech/ccp/component/TogiCountryCodePicker.kt b/ccp/src/main/java/com/togitech/ccp/component/TogiCountryCodePicker.kt index 1856bc4..12890fb 100644 --- a/ccp/src/main/java/com/togitech/ccp/component/TogiCountryCodePicker.kt +++ b/ccp/src/main/java/com/togitech/ccp/component/TogiCountryCodePicker.kt @@ -83,7 +83,8 @@ private const val TAG = "TogiCountryCodePicker" * @param initialCountryPhoneCode Optional country phone code to set the initially selected country. * This takes precedence over [initialCountryIsoCode]. * @param label An optional composable to be used as a label for input field - * @param textStyle An optional [TextStyle] for customizing text style of phone number input field + * @param textStyle An optional [TextStyle] for customizing text style of phone number input field. + * Defaults to MaterialTheme.typography.body1 */ @OptIn(ExperimentalComposeUiApi::class) @Suppress("LongMethod") @@ -126,7 +127,7 @@ fun TogiCountryCodePicker( if (initialPhoneNumber?.startsWith("+") == true) { Log.e(TAG, "initialPhoneNumber must not include the country code") } - if (initialCountryPhoneCode?.startsWith("+") != true) { + if (initialCountryPhoneCode?.run { !startsWith("+") } == true) { Log.e(TAG, "initialCountryPhoneCode must start with +") } mutableStateOf( @@ -153,10 +154,11 @@ fun TogiCountryCodePicker( OutlinedTextField( value = phoneNumber, onValueChange = { enteredPhoneNumber -> - val prefilteredPhoneNumber = - phoneNumberTransformation.preFilter(enteredPhoneNumber.text) - phoneNumber = - TextFieldValue(prefilteredPhoneNumber, TextRange(prefilteredPhoneNumber.length)) + val preFilteredPhoneNumber = phoneNumberTransformation.preFilter(enteredPhoneNumber) + phoneNumber = TextFieldValue( + text = preFilteredPhoneNumber, + selection = TextRange(preFilteredPhoneNumber.length), + ) isNumberValid = validatePhoneNumber( fullPhoneNumber = country.countryPhoneCode + phoneNumber.text, ) @@ -168,11 +170,11 @@ fun TogiCountryCodePicker( .autofill( autofillTypes = listOf(AutofillType.PhoneNumberNational), onFill = { filledPhoneNumber -> - val prefilteredPhoneNumber = + val preFilteredPhoneNumber = phoneNumberTransformation.preFilter(filledPhoneNumber) phoneNumber = TextFieldValue( - prefilteredPhoneNumber, - TextRange(prefilteredPhoneNumber.length), + text = preFilteredPhoneNumber, + selection = TextRange(preFilteredPhoneNumber.length), ) isNumberValid = validatePhoneNumber( fullPhoneNumber = country.countryPhoneCode + phoneNumber.text, diff --git a/ccp/src/main/java/com/togitech/ccp/transformation/PhoneNumberTransformation.kt b/ccp/src/main/java/com/togitech/ccp/transformation/PhoneNumberTransformation.kt index b8e1612..df8f6e6 100644 --- a/ccp/src/main/java/com/togitech/ccp/transformation/PhoneNumberTransformation.kt +++ b/ccp/src/main/java/com/togitech/ccp/transformation/PhoneNumberTransformation.kt @@ -5,6 +5,7 @@ import android.telephony.PhoneNumberUtils import android.text.Selection import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.input.OffsetMapping +import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.text.input.TransformedText import androidx.compose.ui.text.input.VisualTransformation import io.michaelrocks.libphonenumber.android.PhoneNumberUtil @@ -18,6 +19,8 @@ class PhoneNumberTransformation(countryCode: String, context: Context) : VisualT fun preFilter(text: String): String = text.filter { PhoneNumberUtils.isReallyDialable(it) } + fun preFilter(textValue: TextFieldValue): String = preFilter(textValue.text) + override fun filter(text: AnnotatedString): TransformedText { val transformation = reformat(text, Selection.getSelectionEnd(text)) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7a6e645..7647655 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,7 +9,7 @@ compileSdk = "34" # Dependencies android-gradle-plugin = "8.2.0-beta06" -gradle-versions = "0.48.0" +gradle-versions = "0.49.0" detekt = "1.23.1" accompanist = "0.32.0" @@ -25,7 +25,7 @@ compose = "1.5.3" composeCompiler = "1.5.3" kotlinx-coroutines = "1.7.3" -kotlinx-collections-immutable = "0.3.5" +kotlinx-collections-immutable = "0.3.6" libphonenumber = "8.13.17"