android: keep the chat composer above the keyboard (ime insets) #67

Merged
sirius merged 1 commit from wt/chat-ime-insets into main 2026-09-14 04:34:11 +00:00
Owner

Summary

Typing a message in the chat hid both the Send button and the typed body: the keyboard was drawn over them, and the only way to send was to dismiss the keyboard first.

Root cause. MainActivity calls enableEdgeToEdge() (setDecorFitsSystemWindows(window, false)). On API 30+ that stops the framework from resizing the window for the soft keyboard, so the manifest's android:windowSoftInputMode="adjustResize" has nothing left to resize and the IME arrives purely as a window inset. Scaffold's contentWindowInsets covers systemBars only, never ime — nothing consumed it, so the composer row, its Send button and the draft under it were painted behind the keyboard.

Changes

file change
ui/Insets.kt (new) screenContentInsets(): systemBars ∪ ime, applied once at the content root. union is a per-side max, so the keyboard inset (which already covers the navigation bar) and the nav bar are never summed into a double gap. Top is excluded because Scaffold's pad.top is already the app bar's measured height. Marked @Composable — WindowInsets.ime is a composable read.
ui/ChatScreen.kt Scaffold(contentWindowInsets = WindowInsets(0,0,0,0)) + the root consumes the inset; the body region holds weight(1f) in every branch (loading and empty included) so the composer can never be squeezed off the bottom; Send is always drawn instead of being swapped for a spinner (no layout jump under the thumb); ImeAction.Send on the field so the keyboard's own action key sends; focus returns to the field after a send; testTag on composer/input/send.
ui/InviteScreens.kt Both screens: same inset handoff, so Verify / Approve & add under the invite field stay reachable by scrolling.
ui/RotateScreen.kt Same inset handoff for the confirm button under the passphrase field.
ui/UnlockScreen.kt safeDrawingPadding(). This screen has no Scaffold and previously had no inset handling at all — the title drew under the status bar, and Open sat under the keyboard while a passphrase was being typed.

Evidence

Built and exercised on emulator-5554 (AVD ow35, x86_64, API 35) with a debug APK whose sources are byte-identical to this commit (sha256 of all five files compared against the tree that was built):

:app:assembleDebug -Ponionwire.abis=arm64-v8a,x86_64  -> BUILD SUCCESSFUL
:app:testDebugUnitTest                                -> BUILD SUCCESSFUL
app-debug.apk 80,913,831 bytes
sha256 c4addc5c0aa97f6a97ec89a4744247030ff4da9411242b3fcc24bd42c3892072

The chat was reached by pasting this install's own invite back in as a friend (that roster entry's onion is the running node, so a real send completes):

                keyboard closed   keyboard open   (mInputShown=true)
composer        y=2232            y=1380
Send button     y=2253            y=1433
keyboard top          -           y ≈ 1500

The draft text was visible and unobstructed; the message sent both via the Send button and via the keyboard's action key (paper-plane icon = ImeAction.Send), each landing with the ✓✓ delivery marker. Those Y values come from uiautomator dumps — that is the assertion; a screenshot only corroborates it.

Not covered by CI

ci.yml's path allowlist is src/**, crates/**, tests/**, Cargo.*, so an android-only change triggers no job, and android-release.yml runs on v*.*.* tags only. This PR has no green check to look at — the emulator run above is the verification.

Follow-ups (separate cards, deliberately not in this PR)

  1. WalletScreen / RosterScreen root columns are not scrollable — insets alone cannot rescue a confirm button there; they need verticalScroll (or a weighted LazyColumn) first.
  2. RosterScreen:137 — LazyColumn(Modifier.fillMaxSize()) inside a Column claims all remaining height and clips anything after it (the wipe-confirm card). Wants weight(1f).
  3. The chat polls the core every 2s from a LaunchedEffect; one ViewModel-scoped flow would end the wakeup loop.
  4. Auto-scroll to the newest message fires on every append, including while the user is reading history; gate it on "already near the bottom".
  5. maxLines = 4 is now decorative — ImeAction.Send means Enter sends, so there are no manual newlines. Keep Send (chat convention) or drop to a single line: a decision, not an accident.
## Summary Typing a message in the chat hid both the Send button and the typed body: the keyboard was drawn over them, and the only way to send was to dismiss the keyboard first. **Root cause.** `MainActivity` calls `enableEdgeToEdge()` (`setDecorFitsSystemWindows(window, false)`). On API 30+ that stops the framework from resizing the window for the soft keyboard, so the manifest's `android:windowSoftInputMode="adjustResize"` has nothing left to resize and the IME arrives purely as a window inset. `Scaffold`'s `contentWindowInsets` covers `systemBars` only, never `ime` — nothing consumed it, so the composer row, its Send button and the draft under it were painted behind the keyboard. ## Changes | file | change | |---|---| | `ui/Insets.kt` (new) | `screenContentInsets()`: `systemBars ∪ ime`, applied once at the content root. `union` is a per-side max, so the keyboard inset (which already covers the navigation bar) and the nav bar are never summed into a double gap. `Top` is excluded because `Scaffold`'s `pad.top` is already the app bar's measured height. Marked `@Composable` — `WindowInsets.ime` is a composable read. | | `ui/ChatScreen.kt` | `Scaffold(contentWindowInsets = WindowInsets(0,0,0,0))` + the root consumes the inset; the body region holds `weight(1f)` in **every** branch (loading and empty included) so the composer can never be squeezed off the bottom; `Send` is always drawn instead of being swapped for a spinner (no layout jump under the thumb); `ImeAction.Send` on the field so the keyboard's own action key sends; focus returns to the field after a send; `testTag` on composer/input/send. | | `ui/InviteScreens.kt` | Both screens: same inset handoff, so `Verify` / `Approve & add` under the invite field stay reachable by scrolling. | | `ui/RotateScreen.kt` | Same inset handoff for the confirm button under the passphrase field. | | `ui/UnlockScreen.kt` | `safeDrawingPadding()`. This screen has no `Scaffold` and previously had **no** inset handling at all — the title drew under the status bar, and `Open` sat under the keyboard while a passphrase was being typed. | ## Evidence Built and exercised on `emulator-5554` (AVD `ow35`, x86_64, API 35) with a debug APK whose sources are byte-identical to this commit (sha256 of all five files compared against the tree that was built): ``` :app:assembleDebug -Ponionwire.abis=arm64-v8a,x86_64 -> BUILD SUCCESSFUL :app:testDebugUnitTest -> BUILD SUCCESSFUL app-debug.apk 80,913,831 bytes sha256 c4addc5c0aa97f6a97ec89a4744247030ff4da9411242b3fcc24bd42c3892072 ``` The chat was reached by pasting this install's own invite back in as a friend (that roster entry's onion is the running node, so a real send completes): ``` keyboard closed keyboard open (mInputShown=true) composer y=2232 y=1380 Send button y=2253 y=1433 keyboard top - y ≈ 1500 ``` The draft text was visible and unobstructed; the message sent both via the `Send` button and via the keyboard's action key (paper-plane icon = `ImeAction.Send`), each landing with the `✓✓` delivery marker. Those Y values come from `uiautomator` dumps — that is the assertion; a screenshot only corroborates it. ## Not covered by CI `ci.yml`'s path allowlist is `src/**`, `crates/**`, `tests/**`, `Cargo.*`, so an android-only change triggers no job, and `android-release.yml` runs on `v*.*.*` tags only. This PR has no green check to look at — the emulator run above is the verification. ## Follow-ups (separate cards, deliberately not in this PR) 1. `WalletScreen` / `RosterScreen` root columns are not scrollable — insets alone cannot rescue a confirm button there; they need `verticalScroll` (or a weighted `LazyColumn`) first. 2. `RosterScreen:137` — `LazyColumn(Modifier.fillMaxSize())` inside a `Column` claims all remaining height and clips anything after it (the wipe-confirm card). Wants `weight(1f)`. 3. The chat polls the core every 2s from a `LaunchedEffect`; one ViewModel-scoped flow would end the wakeup loop. 4. Auto-scroll to the newest message fires on every append, including while the user is reading history; gate it on "already near the bottom". 5. `maxLines = 4` is now decorative — `ImeAction.Send` means Enter sends, so there are no manual newlines. Keep Send (chat convention) or drop to a single line: a decision, not an accident.
enableEdgeToEdge() sets decorFitsSystemWindows=false, so on API 30+ the framework
no longer resizes the window for the soft keyboard. The manifest's
android:windowSoftInputMode="adjustResize" therefore has nothing to resize and the
IME arrives as an unconsumed window inset; Scaffold's contentWindowInsets covers
systemBars only. Result: the composer row, its Send button and the typed body were
drawn underneath the keyboard and only reachable by dismissing it.

- ui/Insets.kt (new): screenContentInsets() applies systemBars ∪ ime once, at the
  screen's content root. union is per-side max, so the keyboard and the navigation
  bar are never summed; the Top side is excluded because a Scaffold's pad.top is
  already the app bar's measured height (the app bar carries its own status-bar
  inset). @Composable because WindowInsets.ime is a composable read.
- ChatScreen: Scaffold(contentWindowInsets = 0) plus the root consuming the inset;
  the body region holds weight(1f) in every branch (loading and empty included) so
  the composer can never be squeezed off the bottom; Send is always drawn instead
  of being swapped for a spinner (no layout jump under the thumb); the field sets
  ImeAction.Send so the keyboard's own action key sends; focus returns to the
  field after a send; testTag on the composer/input/send.
- InviteScreens (both screens) and RotateScreen: same inset handoff, so the
  Verify / Approve / confirm buttons under a text field stay reachable by scrolling.
- UnlockScreen: safeDrawingPadding(). It had no system-bar insets at all (title
  drawn under the status bar) and its Open button sat under the keyboard while a
  passphrase was being typed.

Verified on emulator-5554 (ow35, x86_64, API 35) with the debug build whose sources
are byte-identical to this commit:

  element        keyboard closed   keyboard open
  composer       y=2232            y=1380
  Send button    y=2253            y=1433
  keyboard top   -                 y≈1500

mInputShown=true while the draft text was visible; the message sent both via the
Send button and via the keyboard's action key (paper-plane = ImeAction.Send), each
landing with the ✓✓ delivery marker. :app:testDebugUnitTest green.

Note: no CI job covers this — ci.yml's path allowlist is src/**, crates/**,
tests/**, Cargo.*, so an android-only change runs nothing, and android-release.yml
only fires on v*.*.* tags.
sirius merged commit ba261a86eb into main 2026-09-14 04:34:11 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/onionwire!67
No description provided.