Modern Apps git

← Modern-Apps.git

taxi: keep inputs visible when the keyboard opens

Commit
f44a54a324be37165bea5d921a16c96b2c93e1fe
Author
Vayun Mathur <[email protected]>
When
2026-12-02 03:05 UTC (4 days ago)
Parents
6e1f3aa
Root cause: Taxi never missed IME insets. The shared Scaffold in
library/ui already unions the IME into the content padding and
consumes it for descendants, every Taxi screen already applied
that padding, and the manifest already uses adjustResize, so
adding imePadding() would have been a no-op. What was missing
was scrollable, height-bounded content: when the keyboard
opened, the scaffold padding shrank non-scrollable columns and
their lower content clipped with no way to reach it.

- Ride screen: the narrow map kept a fixed 220dp above two route
  fields plus an unbounded suggestion list, so the destination
  field and lower suggestions clipped behind the keyboard. The
  map now yields a share of the available height
  (narrowMapHeightDp: 32 percent, capped at the previous 220dp,
  floored at 104dp), the suggestion card is capped at four rows
  and scrolls internally (suggestionListMaxHeightDp), and the
  inputs block scrolls in the space left over. The wide inputs
  pane scrolls the same way. At full window height the mapping
  returns the old 220dp, so screenshot previews are unchanged.
- Lyft/Uber sign-in: the forms applied the scaffold padding in a
  fixed Column, so the code/challenge fields and submit buttons
  clipped once the keyboard shrank them. The columns now scroll
  (the DetailScaffold pattern used by contacts/notes forms).
- Add-card dialog: dialogs have no scaffold, and the four-field
  form was fixed-height. The dialog text is now capped at 480dp
  and scrolls so ZIP, the default toggle and errors stay
  reachable on short windows.

Accounts, current-ride, ride-tracking and the WebView connect
screen have no text inputs (or already scroll) and are
unchanged. No imePadding/navigationBarsPadding was added
anywhere, so there is no double-padding with the scaffold or
the host bottom bar.

Tests: new RideKeyboardLayoutTest pins both height mappings
(tall-window, keyboard-shrunk, floor and cap breakpoints).
Verified in this worktree: ./gradlew :taxi:lint
:taxi:lintVitalRelease :taxi:testDevUnitTest green (run
twice). ktlintCheck stays red at HEAD on pre-existing backlog
in files this change does not touch (data/lyft stores,
androidTest); the changed files add no new ktlint findings
beyond that backlog.

Diff

taxi/src/main/java/com/vayunmathur/taxi/ui/LyftSignInScreen.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/ui/LyftSignInScreen.kt b/taxi/src/main/java/com/vayunmathur/taxi/ui/LyftSignInScreen.ktindex f7d0d0243d..c85e58ec3d 100644--- a/taxi/src/main/java/com/vayunmathur/taxi/ui/LyftSignInScreen.kt+++ b/taxi/src/main/java/com/vayunmathur/taxi/ui/LyftSignInScreen.kt@@ -5,6 +5,8 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf@@ -64,8 +66,11 @@ fun LyftSignInScreen(onBack: () -> Unit) {     }      AppScaffold(title = stringResource(R.string.provider_lyft), onNavigateBack = onBack) { padding ->+        // The scaffold padding already includes the keyboard; scrolling is+        // what keeps the later fields and the submit button reachable once+        // that padding shrinks the column (challenge field, short windows).         Column(-            modifier = Modifier.fillMaxSize().padding(padding).padding(16.dp),+            modifier = Modifier.fillMaxSize().padding(padding).verticalScroll(rememberScrollState()).padding(16.dp),             verticalArrangement = Arrangement.spacedBy(12.dp),         ) {             if (done) {
taxi/src/main/java/com/vayunmathur/taxi/ui/RideContent.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/ui/RideContent.kt b/taxi/src/main/java/com/vayunmathur/taxi/ui/RideContent.ktindex 62069ee9ce..e8e2585f91 100644--- a/taxi/src/main/java/com/vayunmathur/taxi/ui/RideContent.kt+++ b/taxi/src/main/java/com/vayunmathur/taxi/ui/RideContent.kt@@ -2,12 +2,15 @@ package com.vayunmathur.taxi.ui  import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip@@ -100,72 +103,96 @@ internal fun RideWideContent(     ) } +/** Map height on the narrow layout when the window is tall (keyboard closed). */+private const val NARROW_MAP_MAX_DP = 220++/** Map height floor: the smallest map that still gives location context. */+private const val NARROW_MAP_MIN_DP = 104++/**+ * Narrow-layout map height, in dp, for [availableHeightDp] of content height.+ *+ * The shared Scaffold folds the keyboard into the content padding, so when+ * the keyboard opens the content height shrinks by the keyboard's height. A+ * fixed 220.dp map plus the two route fields no longer fit that height and+ * the destination field clipped behind the keyboard; the map therefore+ * yields a share of the available height (capped at the tall-window height,+ * floored so it never vanishes entirely).+ */+internal fun narrowMapHeightDp(availableHeightDp: Int): Int =+    (availableHeightDp * 32 / 100).coerceIn(NARROW_MAP_MIN_DP, NARROW_MAP_MAX_DP)+ @Composable internal fun RideNarrowContent(     data: RideContentData,     events: RideContentEvents,     modifier: Modifier = Modifier, ) {-    Column(modifier) {-        Box(-            Modifier-                .fillMaxWidth()-                .height(220.dp)-                .clip(RoundedCornerShape(bottomStart = 24.dp, bottomEnd = 24.dp)),-        ) {-            VectorMap(cameraState = data.camera, route = data.routeOverlay, modifier = Modifier.fillMaxSize(), options = MapOptions(gestureOptions = GestureOptions.TiltLocked), online = ConnectivityMonitor.isOnline)-            // Overlay pins for pickup and destination, positioned from the live camera-            // projection so they track pan/zoom (same pattern as fooddelivery's map).-            val projection = data.camera.projection-            if (projection != null) {-                data.pickup?.let {-                    MapPin(-                        projection.screenLocationFromPosition(-                            GeoPoint(it.location.longitude, it.location.latitude),-                        ),-                        PickupDotColor,-                    ) { IconMyLocation(tint = Color.White) }-                }-                data.destination?.let {-                    MapPin(-                        projection.screenLocationFromPosition(-                            GeoPoint(it.location.longitude, it.location.latitude),-                        ),-                        DestinationPinColor,-                    ) { IconLocationOn(tint = Color.White) }+    BoxWithConstraints(modifier) {+        val mapHeight = narrowMapHeightDp(maxHeight.value.toInt()).dp+        Column(Modifier.fillMaxSize()) {+            Box(+                Modifier+                    .fillMaxWidth()+                    .height(mapHeight)+                    .clip(RoundedCornerShape(bottomStart = 24.dp, bottomEnd = 24.dp)),+            ) {+                VectorMap(cameraState = data.camera, route = data.routeOverlay, modifier = Modifier.fillMaxSize(), options = MapOptions(gestureOptions = GestureOptions.TiltLocked), online = ConnectivityMonitor.isOnline)+                // Overlay pins for pickup and destination, positioned from the live camera+                // projection so they track pan/zoom (same pattern as fooddelivery's map).+                val projection = data.camera.projection+                if (projection != null) {+                    data.pickup?.let {+                        MapPin(+                            projection.screenLocationFromPosition(+                                GeoPoint(it.location.longitude, it.location.latitude),+                            ),+                            PickupDotColor,+                        ) { IconMyLocation(tint = Color.White) }+                    }+                    data.destination?.let {+                        MapPin(+                            projection.screenLocationFromPosition(+                                GeoPoint(it.location.longitude, it.location.latitude),+                            ),+                            DestinationPinColor,+                        ) { IconLocationOn(tint = Color.White) }+                    }                 }             }-        } -        Column(-            Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 12.dp),-            verticalArrangement = Arrangement.spacedBy(10.dp),-        ) {-            RouteInputs(-                pickupQuery = data.pickupQuery,-                onPickupChange = events.onPickupChange,-                onPickupFocus = events.onPickupFocus,-                onResetPickup = events.onResetPickup,-                destinationQuery = data.destinationQuery,-                onDestinationChange = events.onDestinationChange,-                onDestinationFocus = events.onDestinationFocus,-                onClearDestination = events.onClearDestination,-                onSearch = events.onSearch,-            )+            // Scrolls in the space the (keyboard-shrunk) map leaves, so the+            // destination field stays reachable on short windows too.+            Column(+                Modifier.fillMaxWidth().verticalScroll(rememberScrollState()).padding(horizontal = 16.dp, vertical = 12.dp),+                verticalArrangement = Arrangement.spacedBy(10.dp),+            ) {+                RouteInputs(+                    pickupQuery = data.pickupQuery,+                    onPickupChange = events.onPickupChange,+                    onPickupFocus = events.onPickupFocus,+                    onResetPickup = events.onResetPickup,+                    destinationQuery = data.destinationQuery,+                    onDestinationChange = events.onDestinationChange,+                    onDestinationFocus = events.onDestinationFocus,+                    onClearDestination = events.onClearDestination,+                    onSearch = events.onSearch,+                ) -            if (data.suggestions.isNotEmpty() && data.active != null) {-                SuggestionList(data.suggestions) { events.onSelect(it) }-            } else if (data.searching && data.active != null) {-                LoadingRow(stringResource(R.string.searching))+                if (data.suggestions.isNotEmpty() && data.active != null) {+                    SuggestionList(data.suggestions) { events.onSelect(it) }+                } else if (data.searching && data.active != null) {+                    LoadingRow(stringResource(R.string.searching))+                }             }-        } -        ResultsSection(-            results = data.results,-            comparing = data.comparing,-            hasRoute = data.pickup != null && data.destination != null,-            modifier = Modifier.weight(1f).fillMaxWidth(),-            onBook = events.onBook,-        )+            ResultsSection(+                results = data.results,+                comparing = data.comparing,+                hasRoute = data.pickup != null && data.destination != null,+                modifier = Modifier.weight(1f).fillMaxWidth(),+                onBook = events.onBook,+            )+        }     } }
taxi/src/main/java/com/vayunmathur/taxi/ui/RideInputs.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/ui/RideInputs.kt b/taxi/src/main/java/com/vayunmathur/taxi/ui/RideInputs.ktindex 0642747097..e5b1b947f7 100644--- a/taxi/src/main/java/com/vayunmathur/taxi/ui/RideInputs.kt+++ b/taxi/src/main/java/com/vayunmathur/taxi/ui/RideInputs.kt@@ -10,12 +10,15 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width+import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.runtime.Composable@@ -108,8 +111,11 @@ internal fun RideInputsPane(     modifier: Modifier = Modifier, ) {     Column(modifier) {+        // Scrolls when the keyboard (folded into the scaffold padding by the+        // shared Scaffold) shrinks the panel: the focused field and the+        // suggestion list stay reachable instead of clipping below the keys.         Column(-            Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 12.dp),+            Modifier.fillMaxWidth().verticalScroll(rememberScrollState()).padding(horizontal = 16.dp, vertical = 12.dp),             verticalArrangement = Arrangement.spacedBy(10.dp),         ) {             RouteInputs(@@ -201,10 +207,31 @@ internal fun MapPin(at: DpOffset, color: Color, icon: @Composable () -> Unit) {     } } +/** Height budget of one suggestion row (vertical padding plus name/address lines). */+private const val SUGGESTION_ROW_DP = 68++/** Suggestion rows visible at once; any more scroll inside the card. */+private const val SUGGESTION_MAX_VISIBLE_ROWS = 4++/**+ * Height cap for the suggestion card, in dp: tall enough for every suggestion+ * up to [SUGGESTION_MAX_VISIBLE_ROWS], then flat. Without a cap the card grew+ * without bound inside a non-scrollable column, so opening the keyboard (which+ * the shared Scaffold folds into the content padding) left lower suggestions+ * clipped with no way to scroll to them.+ */+internal fun suggestionListMaxHeightDp(suggestionCount: Int): Int =+    (suggestionCount.coerceAtLeast(0) * SUGGESTION_ROW_DP)+        .coerceAtMost(SUGGESTION_MAX_VISIBLE_ROWS * SUGGESTION_ROW_DP)+ @Composable internal fun SuggestionList(suggestions: List<Place>, onSelect: (Place) -> Unit) {     Card(Modifier.fillMaxWidth()) {-        Column {+        Column(+            Modifier+                .heightIn(max = suggestionListMaxHeightDp(suggestions.size).dp)+                .verticalScroll(rememberScrollState()),+        ) {             suggestions.forEachIndexed { index, place ->                 Row(                     Modifier
taxi/src/main/java/com/vayunmathur/taxi/ui/UberSignInScreen.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/ui/UberSignInScreen.kt b/taxi/src/main/java/com/vayunmathur/taxi/ui/UberSignInScreen.ktindex 880196a709..7a8cd51391 100644--- a/taxi/src/main/java/com/vayunmathur/taxi/ui/UberSignInScreen.kt+++ b/taxi/src/main/java/com/vayunmathur/taxi/ui/UberSignInScreen.kt@@ -5,7 +5,9 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.text.KeyboardOptions+import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf@@ -59,8 +61,11 @@ fun UberSignInScreen(onBack: () -> Unit, onUseWebView: () -> Unit) {     }      AppScaffold(title = stringResource(R.string.provider_uber), onNavigateBack = onBack) { padding ->+        // The scaffold padding already includes the keyboard; scrolling is+        // what keeps the code field, submit and WebView-fallback buttons+        // reachable once that padding shrinks the column.         Column(-            modifier = Modifier.fillMaxSize().padding(padding).padding(16.dp),+            modifier = Modifier.fillMaxSize().padding(padding).verticalScroll(rememberScrollState()).padding(16.dp),             verticalArrangement = Arrangement.spacedBy(12.dp),         ) {             OutlinedTextField(
taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/AddCardDialog.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/AddCardDialog.kt b/taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/AddCardDialog.ktindex f2ab852154..c927650fdf 100644--- a/taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/AddCardDialog.kt+++ b/taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/AddCardDialog.kt@@ -5,9 +5,12 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width+import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.text.KeyboardOptions+import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf@@ -52,7 +55,14 @@ internal fun AddCardDialog(         onDismissRequest = onDismiss,         title = { Text(stringResource(R.string.add_card_title)) },         text = {-            Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {+            // Capped and scrollable: a dialog is not under a scaffold, so when+            // the keyboard covers much of a short window the lower fields+            // (ZIP, default toggle, errors) scroll into view instead of+            // sitting unreachable behind the keys.+            Column(+                modifier = Modifier.heightIn(max = 480.dp).verticalScroll(rememberScrollState()),+                verticalArrangement = Arrangement.spacedBy(8.dp),+            ) {                 OutlinedTextField(                     value = number,                     onValueChange = { number = it },
taxi/src/test/java/com/vayunmathur/taxi/ui/RideKeyboardLayoutTest.kt
diff --git a/taxi/src/test/java/com/vayunmathur/taxi/ui/RideKeyboardLayoutTest.kt b/taxi/src/test/java/com/vayunmathur/taxi/ui/RideKeyboardLayoutTest.ktnew file mode 100644index 0000000000..d1dc1140c8--- /dev/null+++ b/taxi/src/test/java/com/vayunmathur/taxi/ui/RideKeyboardLayoutTest.kt@@ -0,0 +1,62 @@+package com.vayunmathur.taxi.ui++import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/**+ * Pins the keyboard-height mappings behind the Ride screen layout.+ *+ * The shared Scaffold folds the IME into the content padding, so when the+ * keyboard opens the content height handed to these mappings shrinks by the+ * keyboard height. The mappings are the whole fix for "destination field+ * hidden behind the keyboard" (map yields, suggestions stop growing), so+ * their exact breakpoints are pinned here.+ */+class RideKeyboardLayoutTest {++    @Test+    fun narrowMapKeepsFullHeightOnTallWindows() {+        assertEquals(220, narrowMapHeightDp(891))+        assertEquals(220, narrowMapHeightDp(800))+        assertEquals(220, narrowMapHeightDp(688))+    }++    @Test+    fun narrowMapYieldsWhenKeyboardShrinksContent() {+        assertEquals(160, narrowMapHeightDp(500))+        assertEquals(128, narrowMapHeightDp(400))+    }++    @Test+    fun narrowMapNeverVanishes() {+        assertEquals(104, narrowMapHeightDp(312))+        assertEquals(104, narrowMapHeightDp(200))+        assertEquals(104, narrowMapHeightDp(0))+    }++    @Test+    fun narrowMapShrinksMonotonicallyWithAvailableHeight() {+        var previous = narrowMapHeightDp(200)+        for (available in 225..900 step 25) {+            val height = narrowMapHeightDp(available)+            assertTrue(height >= previous, "map grew as window shrank at $available")+            previous = height+        }+    }++    @Test+    fun suggestionListGrowsRowByRowUpToFourRows() {+        assertEquals(0, suggestionListMaxHeightDp(0))+        assertEquals(68, suggestionListMaxHeightDp(1))+        assertEquals(136, suggestionListMaxHeightDp(2))+        assertEquals(272, suggestionListMaxHeightDp(4))+    }++    @Test+    fun suggestionListCapsBeyondFourRows() {+        assertEquals(272, suggestionListMaxHeightDp(5))+        assertEquals(272, suggestionListMaxHeightDp(25))+        assertEquals(0, suggestionListMaxHeightDp(-3))+    }+}