Open a row downwards, from whichever end was pressed
Tapping a group's heading used to send that heading up off the top of the screen and fill the space above it, so the calls appeared on the far side of the control that produced them. The transcript is laid out from the bottom, so every row's bottom edge is what the list holds still and all growth goes upward. The rule now is that the end the reader pressed is the end that must not move. A heading anchors the top, so the row opens downwards under it; the bar at the foot of an open group anchors the bottom, so shutting it from there leaves what follows the group where it is -- which is what already happened, but by accident of the layout rather than on purpose, and would have been lost the moment anything else changed. Bottom is the list's own behaviour and costs nothing. Top is measured rather than calculated: only the layout knows how tall an open group is, so `toggleAnchored` reads where the top edge was, lets the change land, and scrolls by however far it moved. Applied to every row that opens, not just groups -- a lone tool call and a peer message are the same gesture, and one of them opening the other way would be the odder for it.
This commit is contained in:
1 parent
3ecc550c1e
commit
f4d4c82910
3 files changed
+101
-19
No files matched your search
@@ -99,6 +99,20 @@ fun groupToolRuns(items: List<TranscriptItem>): List<TranscriptRow> {
|
||||
return rows
|
||||
}
|
||||
|
||||
/**
|
||||
* Which end of a row a reader acted on, and therefore which end must not move.
|
||||
*
|
||||
* A row has two controls at opposite ends -- the heading that opens it and the bar that shuts it
|
||||
* again -- and the reader's finger is on one of them. Whichever it is has to stay where it is while
|
||||
* the row changes size, or the thing they just pressed slides out from under them. The list anchors
|
||||
* every row's bottom edge by default (see the transcript's `reverseLayout`), so [Bottom] is what
|
||||
* happens on its own and [Top] is what has to be arranged.
|
||||
*/
|
||||
enum class RowEdge {
|
||||
Top,
|
||||
Bottom,
|
||||
}
|
||||
|
||||
/**
|
||||
* Several calls under one heading, closed until somebody asks.
|
||||
*
|
||||
@@ -113,14 +127,15 @@ fun groupToolRuns(items: List<TranscriptItem>): List<TranscriptRow> {
|
||||
fun ToolGroup(
|
||||
group: TranscriptRow.Tools,
|
||||
expanded: Boolean,
|
||||
onToggle: () -> Unit,
|
||||
/** Told which end was pressed, because this row has a control at each -- see [RowEdge]. */
|
||||
onToggle: (RowEdge) -> Unit,
|
||||
isToolExpanded: (String) -> Boolean,
|
||||
onToolToggle: (String) -> Unit,
|
||||
onAnswer: (questionId: String, answers: List<String>) -> Unit,
|
||||
image: @Composable (String) -> Unit,
|
||||
) {
|
||||
if (!expanded) {
|
||||
Card(Modifier.fillMaxWidth().clickable(onClick = onToggle)) {
|
||||
Card(Modifier.fillMaxWidth().clickable { onToggle(RowEdge.Top) }) {
|
||||
Text(
|
||||
"Called ${group.calls.size} tools",
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
@@ -133,7 +148,7 @@ fun ToolGroup(
|
||||
Text(
|
||||
"Called ${group.calls.size} tools",
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
modifier = Modifier.fillMaxWidth().clickable(onClick = onToggle).padding(12.dp),
|
||||
modifier = Modifier.fillMaxWidth().clickable { onToggle(RowEdge.Top) }.padding(12.dp),
|
||||
)
|
||||
group.calls.forEach { call ->
|
||||
ToolCard(
|
||||
@@ -144,7 +159,9 @@ fun ToolGroup(
|
||||
image = image,
|
||||
)
|
||||
}
|
||||
CollapseBar(onToggle)
|
||||
// Shutting it from here anchors the other end: the reader is at the bottom of a long
|
||||
// group, and what they are looking at is what follows it.
|
||||
CollapseBar { onToggle(RowEdge.Bottom) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user