-
Notifications
You must be signed in to change notification settings - Fork 18
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
Visual transformation causing the app to crash on compose v1.7.2 #65
Comments
At the moment, I'm using // PhoneNumberTransformation.kt
@Suppress("AvoidMutableCollections", "AvoidVarsExceptWithDelegate")
private fun reformat(s: CharSequence, cursor: Int): Transformation {
phoneNumberFormatter.clear()
val curIndex = cursor - 1
var formatted: String? = null
var lastNonSeparator = 0.toChar()
var hasCursor = false
s.forEachIndexed { index, char ->
if (PhoneNumberUtils.isNonSeparator(char)) {
if (lastNonSeparator.code != 0) {
formatted = getFormattedNumber(lastNonSeparator, hasCursor)
hasCursor = false
}
lastNonSeparator = char
}
if (index == curIndex) {
hasCursor = true
}
}
if (lastNonSeparator.code != 0) {
formatted = getFormattedNumber(lastNonSeparator, hasCursor)
}
val originalToTransformed = mutableListOf<Int>()
val transformedToOriginal = mutableListOf<Int>()
var specialCharsCount = 0
formatted?.forEachIndexed { index, char ->
if (!PhoneNumberUtils.isNonSeparator(char)) {
specialCharsCount++
} else {
originalToTransformed.add(index)
}
// transformedToOriginal.add(index - specialCharsCount) // Disabled this line
transformedToOriginal.add(maxOf(index - specialCharsCount, 0)) // -> Changed to this line
}
originalToTransformed.add(originalToTransformed.maxOrNull()?.plus(1) ?: 0)
transformedToOriginal.add(transformedToOriginal.maxOrNull()?.plus(1) ?: 0)
return Transformation(formatted, originalToTransformed, transformedToOriginal)
} |
rungxanh1995
changed the title
Visual transformation causing the app to crash
Visual transformation causing the app to crash on compose v1.7.2
Sep 20, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
Recently, entering phone number to the text field is crashing the app.
For example: I want to enter a Canadian phone number
+14165550000
. The code will crash as soon as I've entered "4165550" into the text field.Important note: The code runs well on its own, without any extra dependencies or dependency version upgrades. Then I integrated the library to my project, updated dependency versions and made some necessary edits, it's when the issue arise. The visual transformation logic no longer works in a reliable manner, crashing the app as offset mapping is now flawed.
Refer to my Github fork commits to see the steps I made to edit visual transformation logic to ensure the app doesn't crash.
To Reproduce
Steps to reproduce the behavior:
4165550
Expected behavior
The app shouldn't have crashed, but instead handle visually transforming the input as before.
Smartphone (please complete the following information):
Additional context
Refer to the stack trace error below
The text was updated successfully, but these errors were encountered: