android: keep the chat composer above the keyboard (ime insets)
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.
This commit is contained in:
parent
87fc3ca1b9
commit
08381c47be
5 changed files with 161 additions and 21 deletions
|
|
@ -2,10 +2,12 @@ package com.siriusdevops.onionwire.ui
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.WindowInsets
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
|
|
@ -15,11 +17,16 @@ import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.itemsIndexed
|
import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.LocalContentColor
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
|
|
@ -34,10 +41,14 @@ import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
|
import androidx.compose.ui.focus.focusRequester
|
||||||
import androidx.compose.ui.platform.testTag
|
import androidx.compose.ui.platform.testTag
|
||||||
import androidx.compose.ui.semantics.contentDescription
|
import androidx.compose.ui.semantics.contentDescription
|
||||||
import androidx.compose.ui.semantics.semantics
|
import androidx.compose.ui.semantics.semantics
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
|
import androidx.compose.ui.text.input.KeyboardCapitalization
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import uniffi.onionwire_sdk.ChatMessage
|
import uniffi.onionwire_sdk.ChatMessage
|
||||||
|
|
@ -73,6 +84,18 @@ fun ChatScreen(
|
||||||
var notice by remember { mutableStateOf<String?>(null) }
|
var notice by remember { mutableStateOf<String?>(null) }
|
||||||
val listState = rememberLazyListState()
|
val listState = rememberLazyListState()
|
||||||
|
|
||||||
|
// The composer is the only place a message can be sent from, so after a
|
||||||
|
// send the keyboard is left up and the caret goes back into the field —
|
||||||
|
// the next message is one keystroke away instead of a re-tap.
|
||||||
|
val inputFocus = remember { FocusRequester() }
|
||||||
|
val send: () -> Unit = {
|
||||||
|
if (draft.isNotBlank() && pending == null) {
|
||||||
|
pending = draft
|
||||||
|
draft = ""
|
||||||
|
inputFocus.requestFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Poll: the node appends inbound messages in the background and the retry
|
// Poll: the node appends inbound messages in the background and the retry
|
||||||
// worker moves queued rows along; there is no push channel into the UI in
|
// worker moves queued rows along; there is no push channel into the UI in
|
||||||
// v1, so the delivery markers refresh on the same cadence as the bodies.
|
// v1, so the delivery markers refresh on the same cadence as the bodies.
|
||||||
|
|
@ -139,8 +162,17 @@ fun ChatScreen(
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
// The top bar carries its own status-bar inset; the content root applies
|
||||||
|
// systemBars + IME once (see `screenContentInsets`) so the navigation
|
||||||
|
// bar is not counted twice while the keyboard is up.
|
||||||
|
contentWindowInsets = WindowInsets(0, 0, 0, 0),
|
||||||
) { pad ->
|
) { pad ->
|
||||||
Column(Modifier.padding(pad).fillMaxSize()) {
|
Column(
|
||||||
|
Modifier
|
||||||
|
.padding(pad)
|
||||||
|
.fillMaxSize()
|
||||||
|
.screenContentInsets(),
|
||||||
|
) {
|
||||||
Text(
|
Text(
|
||||||
"onion: $onion",
|
"onion: $onion",
|
||||||
style = MaterialTheme.typography.labelSmall,
|
style = MaterialTheme.typography.labelSmall,
|
||||||
|
|
@ -152,14 +184,21 @@ fun ChatScreen(
|
||||||
val list = messages
|
val list = messages
|
||||||
when {
|
when {
|
||||||
list == null -> {
|
list == null -> {
|
||||||
Spacer(Modifier.height(16.dp))
|
// The body region always claims the leftover height, so the
|
||||||
CircularProgressIndicator(Modifier.padding(16.dp))
|
// composer below it can never be pushed off the bottom —
|
||||||
|
// least of all by the keyboard.
|
||||||
|
Box(Modifier.weight(1f).fillMaxWidth(), contentAlignment = Alignment.Center) {
|
||||||
|
CircularProgressIndicator(Modifier.padding(16.dp))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
list.isEmpty() -> {
|
list.isEmpty() -> {
|
||||||
Column(
|
Column(
|
||||||
Modifier.fillMaxWidth().padding(24.dp),
|
Modifier
|
||||||
verticalArrangement = Arrangement.Center,
|
.weight(1f)
|
||||||
|
.fillMaxWidth()
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(24.dp),
|
||||||
) {
|
) {
|
||||||
Text("No messages", style = MaterialTheme.typography.titleSmall)
|
Text("No messages", style = MaterialTheme.typography.titleSmall)
|
||||||
Spacer(Modifier.height(6.dp))
|
Spacer(Modifier.height(6.dp))
|
||||||
|
|
@ -274,28 +313,52 @@ fun ChatScreen(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The composer sticks to the bottom of the window: `screenContentInsets`
|
||||||
|
// already lifted it above the keyboard, and its row is never allowed
|
||||||
|
// to be squeezed out by the messages above it (they hold the weight).
|
||||||
Row(
|
Row(
|
||||||
Modifier.fillMaxWidth().padding(8.dp),
|
Modifier
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
.fillMaxWidth()
|
||||||
|
.padding(8.dp)
|
||||||
|
.testTag("chat-composer"),
|
||||||
|
verticalAlignment = Alignment.Bottom,
|
||||||
) {
|
) {
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = draft,
|
value = draft,
|
||||||
onValueChange = { draft = it },
|
onValueChange = { draft = it },
|
||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier
|
||||||
|
.weight(1f)
|
||||||
|
.focusRequester(inputFocus)
|
||||||
|
.testTag("chat-input"),
|
||||||
maxLines = 4,
|
maxLines = 4,
|
||||||
label = { Text("message") },
|
label = { Text("message") },
|
||||||
|
// The IME gets its own send affordance: on a phone in
|
||||||
|
// landscape, or with the keyboard covering the button, the
|
||||||
|
// action key is the shortest path to sending.
|
||||||
|
keyboardOptions = KeyboardOptions(
|
||||||
|
capitalization = KeyboardCapitalization.Sentences,
|
||||||
|
imeAction = ImeAction.Send,
|
||||||
|
),
|
||||||
|
keyboardActions = KeyboardActions(onSend = { send() }),
|
||||||
)
|
)
|
||||||
Spacer(Modifier.width(8.dp))
|
Spacer(Modifier.width(8.dp))
|
||||||
if (pending != null) {
|
// Always drawn, never swapped out for a spinner: a button that
|
||||||
CircularProgressIndicator()
|
// changes size under the thumb — or disappears — is how "I hit
|
||||||
} else {
|
// send and nothing happened" gets reported.
|
||||||
Button(
|
Button(
|
||||||
enabled = draft.isNotBlank(),
|
enabled = draft.isNotBlank() && pending == null,
|
||||||
onClick = {
|
onClick = send,
|
||||||
pending = draft
|
modifier = Modifier.testTag("chat-send"),
|
||||||
draft = ""
|
) {
|
||||||
},
|
if (pending != null) {
|
||||||
) { Text("Send") }
|
CircularProgressIndicator(
|
||||||
|
modifier = Modifier.size(14.dp),
|
||||||
|
strokeWidth = 2.dp,
|
||||||
|
color = LocalContentColor.current,
|
||||||
|
)
|
||||||
|
Spacer(Modifier.width(6.dp))
|
||||||
|
}
|
||||||
|
Text("Send")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.siriusdevops.onionwire.ui
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.WindowInsets
|
||||||
|
import androidx.compose.foundation.layout.WindowInsetsSides
|
||||||
|
import androidx.compose.foundation.layout.ime
|
||||||
|
import androidx.compose.foundation.layout.only
|
||||||
|
import androidx.compose.foundation.layout.systemBars
|
||||||
|
import androidx.compose.foundation.layout.union
|
||||||
|
import androidx.compose.foundation.layout.windowInsetsPadding
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The bottom + horizontal window insets one screen's content root must apply
|
||||||
|
* itself.
|
||||||
|
*
|
||||||
|
* `MainActivity` calls `enableEdgeToEdge()`, which means
|
||||||
|
* `setDecorFitsSystemWindows(window, false)`. On API 30+ that stops the
|
||||||
|
* framework from resizing the window for the soft keyboard: the manifest's
|
||||||
|
* `android:windowSoftInputMode="adjustResize"` has nothing left to resize, and
|
||||||
|
* the IME arrives as a *window inset* instead. `Scaffold`'s
|
||||||
|
* `contentWindowInsets` only covers `systemBars`, so anything anchored to the
|
||||||
|
* bottom of the window — the chat composer, a submit button under a text field
|
||||||
|
* — ends up drawn behind the keyboard, reachable only by dismissing it.
|
||||||
|
*
|
||||||
|
* The IME's bottom inset already covers the navigation bar, so the two are
|
||||||
|
* unioned (per-side `max`), never summed: keyboard height while typing,
|
||||||
|
* navigation-bar height otherwise, and no double padding in between.
|
||||||
|
*
|
||||||
|
* The `Top` side is deliberately excluded — a `Scaffold`'s `pad.top` is the app
|
||||||
|
* bar's own measured height, and the app bar carries its own status-bar inset
|
||||||
|
* (`TopAppBarDefaults.windowInsets`).
|
||||||
|
*
|
||||||
|
* Pair every use with `Scaffold(contentWindowInsets = WindowInsets(0, 0, 0, 0))`
|
||||||
|
* so the same inset is not applied twice.
|
||||||
|
*
|
||||||
|
* `@Composable` because `WindowInsets.systemBars` / `WindowInsets.ime` are
|
||||||
|
* composable reads — call it from a composable (every call site is one).
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun Modifier.screenContentInsets(): Modifier =
|
||||||
|
windowInsetsPadding(
|
||||||
|
WindowInsets.systemBars.union(WindowInsets.ime)
|
||||||
|
.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom),
|
||||||
|
)
|
||||||
|
|
@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.WindowInsets
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
|
|
@ -62,9 +63,17 @@ fun ShareInviteScreen(ownerInvite: suspend () -> String, onBack: () -> Unit) {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
// The root applies systemBars + IME itself (see `screenContentInsets`),
|
||||||
|
// so Scaffold must not also pad for the navigation bar.
|
||||||
|
contentWindowInsets = WindowInsets(0, 0, 0, 0),
|
||||||
) { pad ->
|
) { pad ->
|
||||||
Column(
|
Column(
|
||||||
Modifier.padding(pad).fillMaxSize().verticalScroll(rememberScrollState()).padding(16.dp),
|
Modifier
|
||||||
|
.padding(pad)
|
||||||
|
.fillMaxSize()
|
||||||
|
.screenContentInsets()
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(16.dp),
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
"Hand this to one person, over a channel you already trust. " +
|
"Hand this to one person, over a channel you already trust. " +
|
||||||
|
|
@ -149,9 +158,18 @@ fun PasteInviteScreen(
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
// Same inset handoff as the chat composer: with the keyboard up, the
|
||||||
|
// Verify / Approve buttons under the invite field must still be
|
||||||
|
// reachable by scrolling, not by dismissing the keyboard.
|
||||||
|
contentWindowInsets = WindowInsets(0, 0, 0, 0),
|
||||||
) { pad ->
|
) { pad ->
|
||||||
Column(
|
Column(
|
||||||
Modifier.padding(pad).fillMaxSize().verticalScroll(rememberScrollState()).padding(16.dp),
|
Modifier
|
||||||
|
.padding(pad)
|
||||||
|
.fillMaxSize()
|
||||||
|
.screenContentInsets()
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(16.dp),
|
||||||
) {
|
) {
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = raw,
|
value = raw,
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.WindowInsets
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
|
|
@ -59,9 +60,17 @@ fun RotateScreen(
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
// Root owns systemBars + IME (see `screenContentInsets`) so the confirm
|
||||||
|
// button under the passphrase field stays reachable with the keyboard up.
|
||||||
|
contentWindowInsets = WindowInsets(0, 0, 0, 0),
|
||||||
) { pad ->
|
) { pad ->
|
||||||
Column(
|
Column(
|
||||||
Modifier.padding(pad).fillMaxSize().verticalScroll(rememberScrollState()).padding(16.dp),
|
Modifier
|
||||||
|
.padding(pad)
|
||||||
|
.fillMaxSize()
|
||||||
|
.screenContentInsets()
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(16.dp),
|
||||||
) {
|
) {
|
||||||
Text("Rotate onion address?", style = MaterialTheme.typography.titleLarge)
|
Text("Rotate onion address?", style = MaterialTheme.typography.titleLarge)
|
||||||
Spacer(Modifier.height(12.dp))
|
Spacer(Modifier.height(12.dp))
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.safeDrawingPadding
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
|
@ -68,6 +69,10 @@ fun UnlockScreen(
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
|
// This screen has no Scaffold, so its root owns every window inset:
|
||||||
|
// without this the keyboard covers the passphrase field's Open
|
||||||
|
// button and the status bar overlaps the title.
|
||||||
|
.safeDrawingPadding()
|
||||||
.verticalScroll(rememberScrollState())
|
.verticalScroll(rememberScrollState())
|
||||||
.padding(24.dp),
|
.padding(24.dp),
|
||||||
verticalArrangement = Arrangement.Center,
|
verticalArrangement = Arrangement.Center,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue