joelkanyi / kompose-country-code-picker

Kompose Country Code Picker is a Jetpack Compose library based on Material 3 (M3) that provides a country code picker for Android apps.
https://joelkanyi.github.io/kompose-country-code-picker/
Apache License 2.0
154 stars 13 forks source link

IllegalStateException with OffsetMapping.transformedToOriginal in KomposeCountryCodePicker #73

Open kd1398 opened 3 months ago

kd1398 commented 3 months ago

I encountered an issue while using the KomposeCountryCodePicker in my application. When I try to input a more than 8-digit into the field, the application throws an IllegalStateException with the following message:

This error seems to occur due to an invalid mapping being returned by the OffsetMapping.transformedToOriginal method. It appears that the method is trying to map the offset 0 from the transformed text to -1 in the original text, which is not a valid offset.

Steps to reproduce:

  1. Open the application.
  2. Navigate to the screen with the KomposeCountryCodePicker.
  3. Try to input a 10-digit phone number into the field.

Expected behavior: The application should allow the user to input a 10-digit phone number without any issues.

Actual behavior: The application throws an IllegalStateException when the user tries to input a 10-digit phone number.

I am using the following environment:

I would appreciate any help in resolving this issue. Thank you.

joelkanyi commented 3 months ago

Hey @kd1398 thanks for reporting this, do you mind sharing a dummy sample phone number and country code used?

kd1398 commented 3 months ago

Yeah sure, Country code: +1 (CA) Phone number: 2277999888

joelkanyi commented 3 months ago

Just pasted the number and I can see it is valid

canada.webm

joelkanyi commented 3 months ago

Okay got it, which API level are using on your emulator so that I can try and replicate the issue on my end?

kd1398 commented 3 months ago

Sorry for deleting the above video. I am using VanillaIceCream version and device is Pixel 7 Pro API VanillaIceCream

joelkanyi commented 3 months ago

Hey @kd1398 ,

I have tried replicating this issue without success. For now, I have added null safety to the phone number transformer to unblock you. I will keep this issue open to investigate it further.

Kindly try updating the library to version 1.2.5 and let me know if you are still experiencing the crash.

kd1398 commented 3 months ago

Thank you for testing. But in both versions of the API it is crashing with same error

joelkanyi commented 3 months ago

I'd advise you to create a simple project with only the Kompose picker for replication, if it still does not work, push the code to GitHub so that I can check it out

kd1398 commented 3 months ago

Okay I can test that and let you know but I am not able to understand what causing this issue?

kd1398 commented 3 months ago

Hello I tried on different project and it worked but i found out that I am using implementation("androidx.compose.foundation:foundation-layout:1.7.0-beta04") for ContextualFlowRow composable and this is not compatible with this. So if I removed that dependency it was working fine.

So, can you please look into it. Thank you

abdulmanum commented 3 weeks ago

I also facing same issue. And on entering phone number. App crashing. And same I facing issue due to navigation compose and hilt navigation compose implementation(libs.androidx.navigation.compose) implementation(libs.androidx.hilt.navigation.compose)

joelkanyi commented 3 weeks ago

Is it the same reason as this one - https://github.com/joelkanyi/kompose-country-code-picker/issues/73#issuecomment-2261125508

Using some alpha or beta version of a certain library?