Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 77428789cb | |||
| f95e058041 | |||
|
|
9c36814eb3 |
||
| ba261a86eb | |||
|
|
08381c47be |
||
| 87fc3ca1b9 |
4 changed files with 127 additions and 26 deletions
|
|
@ -2,10 +2,12 @@ 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
|
||||
|
|
@ -15,11 +17,16 @@ 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
|
||||
|
|
@ -34,10 +41,14 @@ 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
|
||||
|
|
@ -73,6 +84,18 @@ 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.
|
||||
|
|
@ -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 ->
|
||||
Column(Modifier.padding(pad).fillMaxSize()) {
|
||||
Column(
|
||||
Modifier
|
||||
.padding(pad)
|
||||
.fillMaxSize()
|
||||
.screenContentInsets(),
|
||||
) {
|
||||
Text(
|
||||
"onion: $onion",
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
|
|
@ -152,14 +184,21 @@ fun ChatScreen(
|
|||
val list = messages
|
||||
when {
|
||||
list == null -> {
|
||||
Spacer(Modifier.height(16.dp))
|
||||
CircularProgressIndicator(Modifier.padding(16.dp))
|
||||
// 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))
|
||||
}
|
||||
}
|
||||
|
||||
list.isEmpty() -> {
|
||||
Column(
|
||||
Modifier.fillMaxWidth().padding(24.dp),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
Modifier
|
||||
.weight(1f)
|
||||
.fillMaxWidth()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(24.dp),
|
||||
) {
|
||||
Text("No messages", style = MaterialTheme.typography.titleSmall)
|
||||
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(
|
||||
Modifier.fillMaxWidth().padding(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(8.dp)
|
||||
.testTag("chat-composer"),
|
||||
verticalAlignment = Alignment.Bottom,
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = draft,
|
||||
onValueChange = { draft = it },
|
||||
modifier = Modifier.weight(1f),
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.focusRequester(inputFocus)
|
||||
.testTag("chat-input"),
|
||||
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))
|
||||
if (pending != null) {
|
||||
CircularProgressIndicator()
|
||||
} else {
|
||||
Button(
|
||||
enabled = draft.isNotBlank(),
|
||||
onClick = {
|
||||
pending = draft
|
||||
draft = ""
|
||||
},
|
||||
) { Text("Send") }
|
||||
// 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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
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
|
||||
|
|
@ -31,8 +33,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.LocalClipboardManager
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.platform.ClipEntry
|
||||
import androidx.compose.ui.platform.LocalClipboard
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlinx.coroutines.launch
|
||||
import uniffi.onionwire_sdk.FriendInfo
|
||||
|
|
@ -44,7 +46,8 @@ 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 clip = LocalClipboardManager.current
|
||||
val clipboard = LocalClipboard.current
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
runCatching { ownerInvite() }
|
||||
|
|
@ -62,9 +65,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 ->
|
||||
Column(
|
||||
Modifier.padding(pad).fillMaxSize().verticalScroll(rememberScrollState()).padding(16.dp),
|
||||
Modifier
|
||||
.padding(pad)
|
||||
.fillMaxSize()
|
||||
.screenContentInsets()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(16.dp),
|
||||
) {
|
||||
Text(
|
||||
"Hand this to one person, over a channel you already trust. " +
|
||||
|
|
@ -98,8 +109,12 @@ fun ShareInviteScreen(ownerInvite: suspend () -> String, onBack: () -> Unit) {
|
|||
Spacer(Modifier.height(12.dp))
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Button(onClick = {
|
||||
clip.setText(AnnotatedString(invite!!))
|
||||
copied = true
|
||||
scope.launch {
|
||||
clipboard.setClipEntry(
|
||||
ClipEntry(ClipData.newPlainText("onionwire invite", invite!!)),
|
||||
)
|
||||
copied = true
|
||||
}
|
||||
}) { Text(if (copied) "Copied" else "Copy") }
|
||||
}
|
||||
Spacer(Modifier.height(20.dp))
|
||||
|
|
@ -149,9 +164,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 ->
|
||||
Column(
|
||||
Modifier.padding(pad).fillMaxSize().verticalScroll(rememberScrollState()).padding(16.dp),
|
||||
Modifier
|
||||
.padding(pad)
|
||||
.fillMaxSize()
|
||||
.screenContentInsets()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(16.dp),
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = raw,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ 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
|
||||
|
|
@ -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 ->
|
||||
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)
|
||||
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.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
|
||||
|
|
@ -68,6 +69,10 @@ 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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue