Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version updates and minor changes #40

Merged
merged 4 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions .idea/deploymentTargetDropDown.xml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |



Expand Down
14 changes: 5 additions & 9 deletions ccp/src/main/java/com/togitech/ccp/component/CountryDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Expand Down Expand Up @@ -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),
) {
Expand All @@ -216,7 +213,8 @@ private fun SearchTextField(
}

BasicTextField(
modifier = modifier
modifier = Modifier
.padding(horizontal = DEFAULT_ROW_PADDING)
.height(MIN_TAP_DIMENSION)
.fillMaxWidth()
.focusRequester(requester),
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand All @@ -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,
)
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))

Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

Expand Down