TuleSimon / xMaterialccp

An android Jetpack compose library that provides country code picker for phone number text field using material 3 components
https://www.linkedin.com/mwlite/in/tule-simon-67a202157
58 stars 9 forks source link

Crash, IllegalStateException: OffsetMapping.transformedToOriginal #21

Open franklinblanco opened 20 hours ago

franklinblanco commented 20 hours ago

Hey! First of all I want to thank you a lot for your work on this Widget. It saves a lot of us a bunch of time and looks amazing plus it's extremely customizable. I've integrated it into my upcoming app, and am encountering this error seemingly out of nowhere.

Replication steps

(This is what I did, not necessarily what needs to be done to trigger the crash) Using an American phone number country code, type the number 98612345 (Or any other number that isn't valid, that doesn't trigger the automatic addition of parenthesis) by the time you get to type the number 5 it crashes the entire app.

Possible fix

A google search of the exception says that it's got to do with the visualTransformation applied to the MaterialCountryCodePicker.

visualTransformation = PhoneNumberTransformation(defaultCountry.countryCode.uppercase()),

Complete error log:

FATAL EXCEPTION: main
                 Process: dev.franklinblanco.vanity, PID: 19235
                 java.lang.IllegalStateException: OffsetMapping.transformedToOriginal returned invalid mapping: 0 -> -1 is not in range of original text [0, 8]
                    at androidx.compose.foundation.text.ValidatingOffsetMappingKt.validateTransformedToOriginal(ValidatingOffsetMapping.kt:116)
                    at androidx.compose.foundation.text.ValidatingOffsetMappingKt.throwIfNotValidTransform(ValidatingOffsetMapping.kt:73)
                    at androidx.compose.foundation.text.ValidatingOffsetMappingKt.throwIfNotValidTransform$default(ValidatingOffsetMapping.kt:60)
                    at androidx.compose.foundation.text.ValidatingOffsetMappingKt.filterWithValidation(ValidatingOffsetMapping.kt:35)
                    at androidx.compose.foundation.text.CoreTextFieldKt.CoreTextField(CoreTextField.kt:246)
                    at androidx.compose.foundation.text.BasicTextFieldKt.BasicTextField(BasicTextField.kt:765)
                    at androidx.compose.material3.OutlinedTextFieldKt$OutlinedTextField$3.invoke(OutlinedTextField.kt:383)
                    at androidx.compose.material3.OutlinedTextFieldKt$OutlinedTextField$3.invoke(OutlinedTextField.kt:382)
                    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
                    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
                    at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:401)
                    at androidx.compose.material3.OutlinedTextFieldKt.OutlinedTextField(OutlinedTextField.kt:382)
                    at com.simon.xmaterialccp.component.MaterialCountryCodePickerKt.MaterialCountryCodePicker-EcZREWE(MaterialCountryCodePicker.kt:136)
                    at dev.franklinblanco.vanity.components.flows.PhoneNumberInputFlowKt.PhoneNumberInputFlow(PhoneNumberInputFlow.kt:71)
                    at dev.franklinblanco.vanity.components.flows.PhoneNumberInputFlowKt.PhoneNumberInputFlow$lambda$19(Unknown Source:11)
                    at dev.franklinblanco.vanity.components.flows.PhoneNumberInputFlowKt.$r8$lambda$6CZGCHwJ6-VrzYzxLFRJGdC-qMc(Unknown Source:0)
                    at dev.franklinblanco.vanity.components.flows.PhoneNumberInputFlowKt$$ExternalSyntheticLambda5.invoke(D8$$SyntheticClass:0)
                    at androidx.compose.runtime.RecomposeScopeImpl.compose(RecomposeScopeImpl.kt:192)
                    at androidx.compose.runtime.ComposerImpl.recomposeToGroupEnd(Composer.kt:2825)
                    at androidx.compose.runtime.ComposerImpl.skipCurrentGroup(Composer.kt:3116)
                    at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:3607)
                    at androidx.compose.runtime.ComposerImpl.recompose$runtime_release(Composer.kt:3552)
                    at androidx.compose.runtime.CompositionImpl.recompose(Composition.kt:948)
                    at androidx.compose.runtime.Recomposer.performRecompose(Recomposer.kt:1206)
                    at androidx.compose.runtime.Recomposer.access$performRecompose(Recomposer.kt:132)
                    at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$1.invoke(Recomposer.kt:616)
                    at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$1.invoke(Recomposer.kt:585)
                    at androidx.compose.ui.platform.AndroidUiFrameClock$withFrameNanos$2$callback$1.doFrame(AndroidUiFrameClock.android.kt:41)
                    at androidx.compose.ui.platform.AndroidUiDispatcher.performFrameDispatch(AndroidUiDispatcher.android.kt:109)
                    at androidx.compose.ui.platform.AndroidUiDispatcher.access$performFrameDispatch(AndroidUiDispatcher.android.kt:41)
                    at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.doFrame(AndroidUiDispatcher.android.kt:69)
                    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1404)
                    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1415)
                    at android.view.Choreographer.doCallbacks(Choreographer.java:1015)
                    at android.view.Choreographer.doFrame(Choreographer.java:941)
                    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1389)
                    at android.os.Handler.handleCallback(Handler.java:959)
                    at android.os.Handler.dispatchMessage(Handler.java:100)
                    at android.os.Looper.loopOnce(Looper.java:232)
                    at android.os.Looper.loop(Looper.java:317)
                    at android.app.ActivityThread.main(ActivityThread.java:8705)
17:21:40.006  E     at java.lang.reflect.Method.invoke(Native Method)
                    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
                    Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.runtime.PausableMonotonicFrameClock@503bd9, androidx.compose.ui.platform.MotionDurationScaleImpl@73bc99e, StandaloneCoroutine{Cancelling}@a172c7f, AndroidUiDispatcher@4a6d44c]

Again, thank you so much for your work. I don't expect this to be fixed or you to put more time into it. Just trying to report the issue.

franklinblanco commented 20 hours ago

Using v2.14 of xmaterialccp & Kotlin v2.0.0

TuleSimon commented 17 hours ago

allright am on it @franklinblanco

santanaleonardo commented 43 minutes ago

https://github.com/user-attachments/assets/1a0092d7-66d0-45e7-8a81-89911689d36a

@TuleSimon I managed to reproduce the error but it is not with the same country that is happening with my app, see the attached video.

      Fatal Exception: java.lang.IllegalStateException: OffsetMapping.transformedToOriginal returned invalid mapping: 0 -> -1 is not in range of original text [0, 10]
   at androidx.compose.foundation.text.ValidatingOffsetMappingKt.validateTransformedToOriginal(ValidatingOffsetMapping.kt:28)
   at androidx.compose.foundation.text.ValidatingOffsetMappingKt.throwIfNotValidTransform(ValidatingOffsetMapping.kt:58)
   at androidx.compose.foundation.text.ValidatingOffsetMappingKt.throwIfNotValidTransform$default(ValidatingOffsetMapping.kt:58)
   at androidx.compose.foundation.text.ValidatingOffsetMappingKt.filterWithValidation(ValidatingOffsetMapping.kt:58)
   at androidx.compose.foundation.text.CoreTextFieldKt.CoreTextField(CoreTextField.kt:32)
   at androidx.compose.foundation.text.BasicTextFieldKt.BasicTextField(BasicTextField.kt:6)
   at androidx.compose.material3.OutlinedTextFieldKt$OutlinedTextField$3.invoke(OutlinedTextField.kt:231)
   at androidx.compose.material3.OutlinedTextFieldKt$OutlinedTextField$3.invoke(OutlinedTextField.kt:16)
   at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:54)
   at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:54)
   at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:225)
   at androidx.compose.material3.OutlinedTextFieldKt.OutlinedTextField(OutlinedTextField.kt:16)
   at com.simon.xmaterialccp.component.MaterialCountryCodePickerKt.MaterialCountryCodePicker-EcZREWE(MaterialCountryCodePicker.kt:75)
   at br.com.b8.raffle.ui.raffle.RaffleScreenKt$RaffleScreen$9$2$1.invoke(RaffleScreen.kt:852)
   at br.com.b8.raffle.ui.raffle.RaffleScreenKt$RaffleScreen$9$2$1.invoke(RaffleScreen.kt:852)
   at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:46)
   at androidx.compose.runtime.internal.ComposableLambdaImpl$invoke$1.invoke(ComposableLambdaImpl.java:62)
   at androidx.compose.runtime.internal.ComposableLambdaImpl$invoke$1.invoke(ComposableLambdaImpl.java:52)
   at androidx.compose.runtime.RecomposeScopeImpl.compose(RecomposeScopeImpl.java:585)
   at androidx.compose.runtime.ComposerImpl.recomposeToGroupEnd(Composer.kt:585)
   at androidx.compose.runtime.ComposerImpl.skipCurrentGroup(Composer.kt:130)
   at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:239)
   at androidx.compose.runtime.ComposerImpl.recompose$runtime_release(Composer.kt:30)
   at androidx.compose.runtime.CompositionImpl.recompose(Composition.kt:21)
   at androidx.compose.runtime.Recomposer.performRecompose(Recomposer.kt:113)
   at androidx.compose.runtime.Recomposer.access$performRecompose(Recomposer.kt:113)
   at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$1.invoke(Recomposer.kt:612)
   at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$1.invoke(Recomposer.java:612)
   at androidx.compose.ui.platform.AndroidUiFrameClock$withFrameNanos$2$callback$1.doFrame(AndroidUiFrameClock.android.kt:1)
   at androidx.compose.ui.platform.AndroidUiDispatcher.performFrameDispatch(AndroidUiDispatcher.java:48)
   at androidx.compose.ui.platform.AndroidUiDispatcher.access$performFrameDispatch(AndroidUiDispatcher.java:48)
   at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.doFrame(AndroidUiDispatcher.android.kt:48)
   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1404)
   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1415)
   at android.view.Choreographer.doCallbacks(Choreographer.java:1015)
   at android.view.Choreographer.doFrame(Choreographer.java:941)
   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1389)
   at android.os.Handler.handleCallback(Handler.java:959)
   at android.os.Handler.dispatchMessage(Handler.java:100)
   at android.os.Looper.loopOnce(Looper.java:232)
   at android.os.Looper.loop(Looper.java:317)
   at android.app.ActivityThread.main(ActivityThread.java:8592)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)