From 1a6da003c4408acd4cf40d2b15d54b579f2dfb64 Mon Sep 17 00:00:00 2001 From: Michael Abon Date: Mon, 30 Mar 2026 10:42:12 -0500 Subject: [PATCH 1/2] replace Android-only WindowInsets.isImeVisible with expect/actual for iOS compatibility AnAddressNumberInput.kt used `WindowInsets.isImeVisible`, which is a Jetpack Compose Android-only API unavailable in Compose Multiplatform for iOS targets. Introduce an `isImeVisible()` expect/actual function in ui/util/: - commonMain: expect declaration - androidMain: delegates to WindowInsets.isImeVisible - iosMain: returns false (keyboard detection can be added later) Part of the iOS port effort (#5421). --- .../streetcomplete/ui/util/IsImeVisible.android.kt | 10 ++++++++++ .../quests/address/AnAddressNumberInput.kt | 7 ++----- .../westnordost/streetcomplete/ui/util/IsImeVisible.kt | 7 +++++++ .../streetcomplete/ui/util/IsImeVisible.ios.kt | 6 ++++++ 4 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 app/src/androidMain/kotlin/de/westnordost/streetcomplete/ui/util/IsImeVisible.android.kt create mode 100644 app/src/commonMain/kotlin/de/westnordost/streetcomplete/ui/util/IsImeVisible.kt create mode 100644 app/src/iosMain/kotlin/de/westnordost/streetcomplete/ui/util/IsImeVisible.ios.kt diff --git a/app/src/androidMain/kotlin/de/westnordost/streetcomplete/ui/util/IsImeVisible.android.kt b/app/src/androidMain/kotlin/de/westnordost/streetcomplete/ui/util/IsImeVisible.android.kt new file mode 100644 index 00000000000..f7bd24dc456 --- /dev/null +++ b/app/src/androidMain/kotlin/de/westnordost/streetcomplete/ui/util/IsImeVisible.android.kt @@ -0,0 +1,10 @@ +package de.westnordost.streetcomplete.ui.util + +import androidx.compose.foundation.layout.ExperimentalLayoutApi +import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.foundation.layout.isImeVisible +import androidx.compose.runtime.Composable + +@OptIn(ExperimentalLayoutApi::class) +@Composable +actual fun isImeVisible(): Boolean = WindowInsets.isImeVisible diff --git a/app/src/commonMain/kotlin/de/westnordost/streetcomplete/quests/address/AnAddressNumberInput.kt b/app/src/commonMain/kotlin/de/westnordost/streetcomplete/quests/address/AnAddressNumberInput.kt index 52131effa55..e0c8da7dffa 100644 --- a/app/src/commonMain/kotlin/de/westnordost/streetcomplete/quests/address/AnAddressNumberInput.kt +++ b/app/src/commonMain/kotlin/de/westnordost/streetcomplete/quests/address/AnAddressNumberInput.kt @@ -1,9 +1,6 @@ package de.westnordost.streetcomplete.quests.address -import androidx.compose.foundation.layout.ExperimentalLayoutApi -import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.isImeVisible import androidx.compose.foundation.text.BasicText import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.TextAutoSize @@ -21,6 +18,7 @@ import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.TextFieldValue import de.westnordost.streetcomplete.ui.common.AutoFitTextFieldFontSize +import de.westnordost.streetcomplete.ui.util.isImeVisible import de.westnordost.streetcomplete.ui.common.SwitchKeyboardPopupButton import de.westnordost.streetcomplete.ui.common.TextField2 @@ -30,7 +28,6 @@ import de.westnordost.streetcomplete.ui.common.TextField2 * - one can switch between text and number software keyboard * - a suggestion can be displayed that is sized the same as the actual input, only with less alpha * - certain common text styling (monospace, centered) */ -@OptIn(ExperimentalLayoutApi::class) @Composable fun AnAddressNumberInput( value: String, @@ -49,7 +46,7 @@ fun AnAddressNumberInput( val keyboardType = if (isAbc) KeyboardType.Text else KeyboardType.Number var isFocused by remember { mutableStateOf(false) } - val showSwitchKeyboardPopup = isFocused && WindowInsets.isImeVisible + val showSwitchKeyboardPopup = isFocused && isImeVisible() ProvideTextStyle(LocalTextStyle.current.copy( // to avoid the size of the text changing when going from e.g. "123j" to "123k" diff --git a/app/src/commonMain/kotlin/de/westnordost/streetcomplete/ui/util/IsImeVisible.kt b/app/src/commonMain/kotlin/de/westnordost/streetcomplete/ui/util/IsImeVisible.kt new file mode 100644 index 00000000000..c1690ae19ca --- /dev/null +++ b/app/src/commonMain/kotlin/de/westnordost/streetcomplete/ui/util/IsImeVisible.kt @@ -0,0 +1,7 @@ +package de.westnordost.streetcomplete.ui.util + +import androidx.compose.runtime.Composable + +/** Whether the software keyboard (IME) is currently visible. */ +@Composable +expect fun isImeVisible(): Boolean diff --git a/app/src/iosMain/kotlin/de/westnordost/streetcomplete/ui/util/IsImeVisible.ios.kt b/app/src/iosMain/kotlin/de/westnordost/streetcomplete/ui/util/IsImeVisible.ios.kt new file mode 100644 index 00000000000..00fd147512d --- /dev/null +++ b/app/src/iosMain/kotlin/de/westnordost/streetcomplete/ui/util/IsImeVisible.ios.kt @@ -0,0 +1,6 @@ +package de.westnordost.streetcomplete.ui.util + +import androidx.compose.runtime.Composable + +@Composable +actual fun isImeVisible(): Boolean = false From 01cff5c6f3d719b91c48b581e4ec40c8ba4fd031 Mon Sep 17 00:00:00 2001 From: Tobias Zwick Date: Thu, 2 Apr 2026 11:36:42 +0200 Subject: [PATCH 2/2] add todo comment --- .../kotlin/de/westnordost/streetcomplete/ui/util/IsImeVisible.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/commonMain/kotlin/de/westnordost/streetcomplete/ui/util/IsImeVisible.kt b/app/src/commonMain/kotlin/de/westnordost/streetcomplete/ui/util/IsImeVisible.kt index c1690ae19ca..03a3c4809d9 100644 --- a/app/src/commonMain/kotlin/de/westnordost/streetcomplete/ui/util/IsImeVisible.kt +++ b/app/src/commonMain/kotlin/de/westnordost/streetcomplete/ui/util/IsImeVisible.kt @@ -4,4 +4,5 @@ import androidx.compose.runtime.Composable /** Whether the software keyboard (IME) is currently visible. */ @Composable +// TODO CMP: this is necessary as long as https://youtrack.jetbrains.com/issue/CMP-9906/Commonize-WindowInsets.isVisible-functions is not implemented expect fun isImeVisible(): Boolean