Skip to content

Fix crash on Compose 1.7; Update dependencies#67

Open
dhritzkiv wants to merge 9 commits intojump-sdk:masterfrom
dhritzkiv:fix/crash-on-compose-1.7
Open

Fix crash on Compose 1.7; Update dependencies#67
dhritzkiv wants to merge 9 commits intojump-sdk:masterfrom
dhritzkiv:fix/crash-on-compose-1.7

Conversation

@dhritzkiv
Copy link
Copy Markdown

@dhritzkiv dhritzkiv commented Sep 22, 2024

After updating to Jetpack Compose 1.7, this library would lead to a crash (#65) in our app after typing about 7 or 8 digits (for a Canadian / US number, at least):

Process: com.togitech.togii, PID: 15552
java.lang.IllegalStateException: OffsetMapping.transformedToOriginal returned invalid mapping: 0 -> -1 is not in range of original text [0, 8]

I suspect this occurs when a number starts to be formatted-as-you-type with parenthesis. E.g.:416555 would be formatted as 416-555, while 4165550 would be formatted as (416)-555-0.

I suspect that previous versions of Compose treated negative indexes passed to transformedToOriginal as undefined behaviour, but in 1.7 it's more defined and leads to a crash.

In any case, my colleague came up with a quick fix by clamping -1 to 0. Not sure if this is the correct fix, but this has fixed the crash for us, and has had no negative outcomes in our code.

While the fix was one line of code, it was necessary to increase the Jetpack Compose version to at least 1.7. However, in addition to updating Jetpack Compose to 1.7, we've also updated the library to use Kotlin 2.0; to use the Compose BOM (instead of defining individual libraries/versions); and updated some other dependencies.

@sonarqubecloud
Copy link
Copy Markdown

@dave-becker-accesso
Copy link
Copy Markdown

Thanks for the fix my dude

@dhritzkiv dhritzkiv changed the title Fix crash on Compose 1.7 Fix crash on Compose 1.7; Update dependencies Nov 14, 2024
Copy link
Copy Markdown

@adrianegraphene adrianegraphene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please approve. This is great. Fixed my long-time frustrating issues with compose 1.7.0
would be very helpful to get this approved and added as a new version. Currently, I had to fork this and release my own version (do not want to do that...) - Please consider approving and saving other devs long frustrating hours...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants