timeline fixups

This commit is contained in:
Henry Hiles 2026-11-09 10:58:08 -05:00
commit ac31fbb74d
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs

View file

@ -40,6 +40,16 @@ class const ChatTimeline({
isHighlighted: scroll.highlightedEvent == eventRowId,
);
/// Where the row with [key] now is in [rows], so its element moves with it
/// when rows are added before it, rather than being rebuilt by index.
int? indexOf(IList<int> rows, Key key) => switch (key) {
EventRowKey(:final rowId) => switch (rows.indexOf(rowId)) {
-1 => null,
final index => index,
},
_ => null,
};
@override
Widget build(BuildContext context) => LayoutBuilder(
builder: (context, constraints) => TweenAnimationBuilder(
@ -66,6 +76,7 @@ class const ChatTimeline({
SuperSliverList.builder(
itemCount: scroll.liveRows.length,
findChildIndexCallback: (key) => indexOf(scroll.liveRows, key),
itemBuilder: (_, index) => eventRow(
scroll.liveRows[index],
index > 0
@ -78,6 +89,8 @@ class const ChatTimeline({
SuperSliverList.builder(
key: scroll.centerKey,
itemCount: scroll.historyRows.length,
findChildIndexCallback: (key) =>
indexOf(scroll.historyRows, key),
itemBuilder: (_, index) => eventRow(
scroll.historyRows[index],
scroll.historyRows.getOrNull(index + 1),