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..03a3c4809d9 --- /dev/null +++ b/app/src/commonMain/kotlin/de/westnordost/streetcomplete/ui/util/IsImeVisible.kt @@ -0,0 +1,8 @@ +package de.westnordost.streetcomplete.ui.util + +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 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