Compare commits

..
4 changed files with 26 additions and 127 deletions

View file

@ -2,12 +2,10 @@ package com.siriusdevops.onionwire.ui
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
@ -17,16 +15,11 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollState
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.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
@ -41,14 +34,10 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
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.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
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 kotlinx.coroutines.delay
import uniffi.onionwire_sdk.ChatMessage
@ -84,18 +73,6 @@ fun ChatScreen(
var notice by remember { mutableStateOf<String?>(null) }
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
// 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.
@ -162,17 +139,8 @@ 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 ->
Column(
Modifier
.padding(pad)
.fillMaxSize()
.screenContentInsets(),
) {
Column(Modifier.padding(pad).fillMaxSize()) {
Text(
"onion: $onion",
style = MaterialTheme.typography.labelSmall,
@ -184,21 +152,14 @@ fun ChatScreen(
val list = messages
when {
list == null -> {
// The body region always claims the leftover height, so the
// 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))
}
Spacer(Modifier.height(16.dp))
CircularProgressIndicator(Modifier.padding(16.dp))
}
list.isEmpty() -> {
Column(
Modifier
.weight(1f)
.fillMaxWidth()
.verticalScroll(rememberScrollState())
.padding(24.dp),
Modifier.fillMaxWidth().padding(24.dp),
verticalArrangement = Arrangement.Center,
) {
Text("No messages", style = MaterialTheme.typography.titleSmall)
Spacer(Modifier.height(6.dp))
@ -313,52 +274,28 @@ 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(
Modifier
.fillMaxWidth()
.padding(8.dp)
.testTag("chat-composer"),
verticalAlignment = Alignment.Bottom,
Modifier.fillMaxWidth().padding(8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
OutlinedTextField(
value = draft,
onValueChange = { draft = it },
modifier = Modifier
.weight(1f)
.focusRequester(inputFocus)
.testTag("chat-input"),
modifier = Modifier.weight(1f),
maxLines = 4,
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))
// Always drawn, never swapped out for a spinner: a button that
// changes size under the thumb — or disappears — is how "I hit
// send and nothing happened" gets reported.
Button(
enabled = draft.isNotBlank() && pending == null,
onClick = send,
modifier = Modifier.testTag("chat-send"),
) {
if (pending != null) {
CircularProgressIndicator(
modifier = Modifier.size(14.dp),
strokeWidth = 2.dp,
color = LocalContentColor.current,
)
Spacer(Modifier.width(6.dp))
}
Text("Send")
if (pending != null) {
CircularProgressIndicator()
} else {
Button(
enabled = draft.isNotBlank(),
onClick = {
pending = draft
draft = ""
},
) { Text("Send") }
}
}
}

View file

@ -1,11 +1,9 @@
package com.siriusdevops.onionwire.ui
import android.content.ClipData
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
@ -33,8 +31,8 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ClipEntry
import androidx.compose.ui.platform.LocalClipboard
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch
import uniffi.onionwire_sdk.FriendInfo
@ -46,8 +44,7 @@ fun ShareInviteScreen(ownerInvite: suspend () -> String, onBack: () -> Unit) {
var invite by remember { mutableStateOf<String?>(null) }
var error by remember { mutableStateOf<String?>(null) }
var copied by remember { mutableStateOf(false) }
val clipboard = LocalClipboard.current
val scope = rememberCoroutineScope()
val clip = LocalClipboardManager.current
LaunchedEffect(Unit) {
runCatching { ownerInvite() }
@ -65,17 +62,9 @@ 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 ->
Column(
Modifier
.padding(pad)
.fillMaxSize()
.screenContentInsets()
.verticalScroll(rememberScrollState())
.padding(16.dp),
Modifier.padding(pad).fillMaxSize().verticalScroll(rememberScrollState()).padding(16.dp),
) {
Text(
"Hand this to one person, over a channel you already trust. " +
@ -109,12 +98,8 @@ fun ShareInviteScreen(ownerInvite: suspend () -> String, onBack: () -> Unit) {
Spacer(Modifier.height(12.dp))
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
Button(onClick = {
scope.launch {
clipboard.setClipEntry(
ClipEntry(ClipData.newPlainText("onionwire invite", invite!!)),
)
copied = true
}
clip.setText(AnnotatedString(invite!!))
copied = true
}) { Text(if (copied) "Copied" else "Copy") }
}
Spacer(Modifier.height(20.dp))
@ -164,18 +149,9 @@ 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 ->
Column(
Modifier
.padding(pad)
.fillMaxSize()
.screenContentInsets()
.verticalScroll(rememberScrollState())
.padding(16.dp),
Modifier.padding(pad).fillMaxSize().verticalScroll(rememberScrollState()).padding(16.dp),
) {
OutlinedTextField(
value = raw,

View file

@ -4,7 +4,6 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
@ -60,17 +59,9 @@ 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 ->
Column(
Modifier
.padding(pad)
.fillMaxSize()
.screenContentInsets()
.verticalScroll(rememberScrollState())
.padding(16.dp),
Modifier.padding(pad).fillMaxSize().verticalScroll(rememberScrollState()).padding(16.dp),
) {
Text("Rotate onion address?", style = MaterialTheme.typography.titleLarge)
Spacer(Modifier.height(12.dp))

View file

@ -8,7 +8,6 @@ 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.layout.safeDrawingPadding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
@ -69,10 +68,6 @@ fun UnlockScreen(
Column(
modifier = Modifier
.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())
.padding(24.dp),
verticalArrangement = Arrangement.Center,