add focus stuff
good for a11y, and for seeing times on mobile
This commit is contained in:
parent
3cfe6a3681
commit
43ce320987
6 changed files with 120 additions and 68 deletions
|
|
@ -82,6 +82,7 @@ class const EventRenderer(
|
|||
final colorScheme = theme.colorScheme;
|
||||
final focusNode = useFocusNode();
|
||||
useListenable(focusNode);
|
||||
final pointerDown = useRef<(Offset, Duration)?>(null);
|
||||
final senderRecognizer = useTapRecognizer();
|
||||
|
||||
final (event, previousEvent) = ref.watch(
|
||||
|
|
@ -212,6 +213,7 @@ class const EventRenderer(
|
|||
? null
|
||||
: () => onOpenThread!(event.eventId),
|
||||
isGrouped: isGrouped,
|
||||
showTime: focusNode.hasPrimaryFocus,
|
||||
maxLines: maxLines,
|
||||
textOnly: textOnly,
|
||||
)
|
||||
|
|
@ -585,7 +587,10 @@ class const EventRenderer(
|
|||
if (textOnly)
|
||||
child
|
||||
else ...[
|
||||
Builder(
|
||||
// Spacing between groups is outside the highlight, so it's even
|
||||
Padding(
|
||||
padding: .only(top: isGrouped ? 0 : 4),
|
||||
child: Builder(
|
||||
builder: (context) => FocusableActionDetector(
|
||||
focusNode: focusNode,
|
||||
actions: contextMenuCallback == null
|
||||
|
|
@ -607,19 +612,51 @@ class const EventRenderer(
|
|||
),
|
||||
},
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
// Rounds every corner, as HighlightWrapper's clip only
|
||||
// reaches the ones at the row's edges
|
||||
borderRadius: .circular(12),
|
||||
color: focusNode.hasPrimaryFocus
|
||||
? theme.colorScheme.surfaceContainerHighest
|
||||
: null,
|
||||
),
|
||||
// Tapping focuses the event, e.g. showing when grouped
|
||||
// messages were sent. A Listener, unlike a GestureDetector,
|
||||
// sees taps without taking them from links, media and the
|
||||
// like.
|
||||
child: Listener(
|
||||
behavior: .translucent,
|
||||
onPointerDown: (pointer) => pointerDown.value = (
|
||||
pointer.position,
|
||||
pointer.timeStamp,
|
||||
),
|
||||
onPointerUp: (pointer) {
|
||||
if (pointerDown.value
|
||||
case (final position, final timeStamp)
|
||||
when (pointer.position - position).distance <
|
||||
kTouchSlop &&
|
||||
pointer.timeStamp - timeStamp <
|
||||
kLongPressTimeout) {
|
||||
focusNode.hasPrimaryFocus
|
||||
? focusNode.unfocus()
|
||||
: focusNode.requestFocus();
|
||||
}
|
||||
pointerDown.value = null;
|
||||
},
|
||||
onPointerCancel: (_) => pointerDown.value = null,
|
||||
child: GestureDetector(
|
||||
onSecondaryTapUp: contextMenuCallback,
|
||||
onLongPressStart: contextMenuCallback,
|
||||
child: SwipeToReply(
|
||||
onSwipe: onSwipe,
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8)
|
||||
.copyWith(top: isGrouped ? 0 : 8),
|
||||
// Even on every side, so the highlight's centered. Lists
|
||||
// add more space at their edges.
|
||||
padding: .symmetric(
|
||||
horizontal: 4,
|
||||
vertical: child is MessageRenderer ? 4 : 0,
|
||||
),
|
||||
child: Wrap(
|
||||
verticalDirection: .up,
|
||||
spacing: 6,
|
||||
|
|
@ -637,6 +674,8 @@ class const EventRenderer(
|
|||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
...[
|
||||
if (child is! MessageRenderer) ReactionRow(event),
|
||||
|
|
|
|||
|
|
@ -38,6 +38,10 @@ class const MessageRenderer(
|
|||
final VoidCallback? onTapThread,
|
||||
final bool textOnly = false,
|
||||
final bool isGrouped = false,
|
||||
|
||||
/// Whether grouped messages show when they were sent, which they otherwise
|
||||
/// only do on hover.
|
||||
final bool showTime = false,
|
||||
final int? maxLines,
|
||||
super.key,
|
||||
}) extends HookConsumerWidget {
|
||||
|
|
@ -173,12 +177,11 @@ class const MessageRenderer(
|
|||
children: [
|
||||
if (!textOnly)
|
||||
if (isGrouped)
|
||||
// Shows when the message was sent on hover, as grouped messages
|
||||
// have no header
|
||||
// When the message was sent, as grouped messages have no header
|
||||
SizedBox(
|
||||
width: 40,
|
||||
child: Visibility.maintain(
|
||||
visible: hovered.value,
|
||||
visible: hovered.value || showTime,
|
||||
child: Padding(
|
||||
padding: .only(top: 14),
|
||||
child: Tooltip(
|
||||
|
|
@ -213,7 +216,7 @@ class const MessageRenderer(
|
|||
],
|
||||
),
|
||||
Card(
|
||||
margin: textOnly ? .zero : .only(bottom: 4),
|
||||
margin: .zero,
|
||||
color: textOnly
|
||||
? Colors.transparent
|
||||
: ref.watch(
|
||||
|
|
|
|||
|
|
@ -24,7 +24,11 @@ class const ChatTimeline({
|
|||
int eventRowId,
|
||||
int? previousEventRowId, {
|
||||
required Key key,
|
||||
}) => HighlightWrapper(
|
||||
}) => Padding(
|
||||
key: key,
|
||||
// Spacing at the edges, outside events' focus highlight
|
||||
padding: .symmetric(horizontal: 4),
|
||||
child: HighlightWrapper(
|
||||
// To work around an AWFUL SuperSliverList bug
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(minHeight: 0.01),
|
||||
|
|
@ -40,8 +44,8 @@ class const ChatTimeline({
|
|||
threadRoot: chat.threadRoot,
|
||||
),
|
||||
),
|
||||
key: key,
|
||||
isHighlighted: scroll.highlightedEvent == eventRowId,
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ final class const PinnedEventsDrawer(
|
|||
jumpToEvent(rowId);
|
||||
},
|
||||
child: Padding(
|
||||
padding: .symmetric(vertical: 4),
|
||||
padding: .symmetric(vertical: 4, horizontal: 4),
|
||||
child: IgnorePointer(
|
||||
child: EventRenderer(
|
||||
rowId,
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ final class const SearchDrawer(
|
|||
jumpToEvent(rowId);
|
||||
},
|
||||
child: Padding(
|
||||
padding: .symmetric(vertical: 4),
|
||||
padding: .symmetric(vertical: 4, horizontal: 4),
|
||||
child: IgnorePointer(
|
||||
child: EventRenderer(
|
||||
rowId,
|
||||
|
|
|
|||
|
|
@ -170,8 +170,14 @@ class const NotificationsList({super.key})
|
|||
|
||||
await ref.focusRoom(roomId, rowId);
|
||||
},
|
||||
child: Padding(
|
||||
padding: .symmetric(horizontal: 4),
|
||||
child: IgnorePointer(
|
||||
child: EventRenderer(rowId, roomId: roomId),
|
||||
child: EventRenderer(
|
||||
rowId,
|
||||
roomId: roomId,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
isHighlighted: isHighlighted,
|
||||
|
|
|
|||
Loading…
Reference in a new issue