Skip to content

Commit 9f5fdaa

Browse files
authored
Replace Android-only WindowInsets.isImeVisible with expect/actual for iOS compatibility (#6795)
1 parent ad55642 commit 9f5fdaa

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package de.westnordost.streetcomplete.ui.util
2+
3+
import androidx.compose.foundation.layout.ExperimentalLayoutApi
4+
import androidx.compose.foundation.layout.WindowInsets
5+
import androidx.compose.foundation.layout.isImeVisible
6+
import androidx.compose.runtime.Composable
7+
8+
@OptIn(ExperimentalLayoutApi::class)
9+
@Composable
10+
actual fun isImeVisible(): Boolean = WindowInsets.isImeVisible

app/src/commonMain/kotlin/de/westnordost/streetcomplete/quests/address/AnAddressNumberInput.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package de.westnordost.streetcomplete.quests.address
22

3-
import androidx.compose.foundation.layout.ExperimentalLayoutApi
4-
import androidx.compose.foundation.layout.WindowInsets
53
import androidx.compose.foundation.layout.fillMaxWidth
6-
import androidx.compose.foundation.layout.isImeVisible
74
import androidx.compose.foundation.text.BasicText
85
import androidx.compose.foundation.text.KeyboardOptions
96
import androidx.compose.foundation.text.TextAutoSize
@@ -21,6 +18,7 @@ import androidx.compose.ui.text.font.FontFamily
2118
import androidx.compose.ui.text.input.KeyboardType
2219
import androidx.compose.ui.text.input.TextFieldValue
2320
import de.westnordost.streetcomplete.ui.common.AutoFitTextFieldFontSize
21+
import de.westnordost.streetcomplete.ui.util.isImeVisible
2422
import de.westnordost.streetcomplete.ui.common.SwitchKeyboardPopupButton
2523
import de.westnordost.streetcomplete.ui.common.TextField2
2624

@@ -30,7 +28,6 @@ import de.westnordost.streetcomplete.ui.common.TextField2
3028
* - one can switch between text and number software keyboard
3129
* - a suggestion can be displayed that is sized the same as the actual input, only with less alpha
3230
* - certain common text styling (monospace, centered) */
33-
@OptIn(ExperimentalLayoutApi::class)
3431
@Composable
3532
fun AnAddressNumberInput(
3633
value: String,
@@ -49,7 +46,7 @@ fun AnAddressNumberInput(
4946
val keyboardType = if (isAbc) KeyboardType.Text else KeyboardType.Number
5047

5148
var isFocused by remember { mutableStateOf(false) }
52-
val showSwitchKeyboardPopup = isFocused && WindowInsets.isImeVisible
49+
val showSwitchKeyboardPopup = isFocused && isImeVisible()
5350

5451
ProvideTextStyle(LocalTextStyle.current.copy(
5552
// to avoid the size of the text changing when going from e.g. "123j" to "123k"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package de.westnordost.streetcomplete.ui.util
2+
3+
import androidx.compose.runtime.Composable
4+
5+
/** Whether the software keyboard (IME) is currently visible. */
6+
@Composable
7+
// TODO CMP: this is necessary as long as https://youtrack.jetbrains.com/issue/CMP-9906/Commonize-WindowInsets.isVisible-functions is not implemented
8+
expect fun isImeVisible(): Boolean
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package de.westnordost.streetcomplete.ui.util
2+
3+
import androidx.compose.runtime.Composable
4+
5+
@Composable
6+
actual fun isImeVisible(): Boolean = TODO()

0 commit comments

Comments
 (0)