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
149 stars 14 forks source link

Airplane mode issue #15

Closed gerigorila closed 10 months ago

gerigorila commented 10 months ago

Description: When airplane mode is enabled on the device, the app crashes because it is unable to get the country code from the SIM card. The KomposeCountryCodePicker component does not have a default country code set, so it throws a NoSuchElementException when it tries to get the country code from the empty SIM card data.

Steps to reproduce: Enable airplane mode on the device. Open the app and navigate to the screen where the KomposeCountryCodePicker component is used.

Expected behavior: The app should not crash when airplane mode is enabled. The KomposeCountryCodePicker component should either set a default country code or handle the case where there is no SIM card data available.

Actual behavior: The app crashes with a NoSuchElementException.

Device info: Google Pixel 2XL api level 30

Exception code:

             java.util.NoSuchElementException: Collection contains no element matching the predicate.
                at com.joelkanyi.jcomposecountrycodepicker.component.KomposeCountryCodePickerKt$KomposeCountryCodePicker$2.invoke(KomposeCountryCodePicker.kt:297)
                at com.joelkanyi.jcomposecountrycodepicker.component.KomposeCountryCodePickerKt$KomposeCountryCodePicker$2.invoke(KomposeCountryCodePicker.kt:98)
                at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
                at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
                at androidx.compose.material3.SurfaceKt$Surface$1.invoke(Surface.kt:132)
                at androidx.compose.material3.SurfaceKt$Surface$1.invoke(Surface.kt:114)
                at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
                at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
                at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
                at androidx.compose.material3.SurfaceKt.Surface-T9BRK9s(Surface.kt:111)
joelkanyi commented 10 months ago

Thank you @gerigorila for the issue, let me investigate it

joelkanyi commented 10 months ago

Please update to 1.0.8 and confirm if the issue is fixed, also there is a parameter defaultCountryCode = "tz" that you can use to set your default country code.