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 colorScheme = theme.colorScheme;
|
||||||
final focusNode = useFocusNode();
|
final focusNode = useFocusNode();
|
||||||
useListenable(focusNode);
|
useListenable(focusNode);
|
||||||
|
final pointerDown = useRef<(Offset, Duration)?>(null);
|
||||||
final senderRecognizer = useTapRecognizer();
|
final senderRecognizer = useTapRecognizer();
|
||||||
|
|
||||||
final (event, previousEvent) = ref.watch(
|
final (event, previousEvent) = ref.watch(
|
||||||
|
|
@ -212,6 +213,7 @@ class const EventRenderer(
|
||||||
? null
|
? null
|
||||||
: () => onOpenThread!(event.eventId),
|
: () => onOpenThread!(event.eventId),
|
||||||
isGrouped: isGrouped,
|
isGrouped: isGrouped,
|
||||||
|
showTime: focusNode.hasPrimaryFocus,
|
||||||
maxLines: maxLines,
|
maxLines: maxLines,
|
||||||
textOnly: textOnly,
|
textOnly: textOnly,
|
||||||
)
|
)
|
||||||
|
|
@ -585,51 +587,88 @@ class const EventRenderer(
|
||||||
if (textOnly)
|
if (textOnly)
|
||||||
child
|
child
|
||||||
else ...[
|
else ...[
|
||||||
Builder(
|
// Spacing between groups is outside the highlight, so it's even
|
||||||
builder: (context) => FocusableActionDetector(
|
Padding(
|
||||||
focusNode: focusNode,
|
padding: .only(top: isGrouped ? 0 : 4),
|
||||||
actions: contextMenuCallback == null
|
child: Builder(
|
||||||
? null
|
builder: (context) => FocusableActionDetector(
|
||||||
: {
|
focusNode: focusNode,
|
||||||
ActivateIntent: CallbackAction(
|
actions: contextMenuCallback == null
|
||||||
onInvoke: (_) {
|
? null
|
||||||
final renderBox =
|
: {
|
||||||
context.findRenderObject() as RenderBox;
|
ActivateIntent: CallbackAction(
|
||||||
final topLeft = renderBox.localToGlobal(
|
onInvoke: (_) {
|
||||||
Offset.zero,
|
final renderBox =
|
||||||
);
|
context.findRenderObject() as RenderBox;
|
||||||
context.showAdaptiveMenu(
|
final topLeft = renderBox.localToGlobal(
|
||||||
getEventOptions!(event).toList(),
|
Offset.zero,
|
||||||
globalPosition: topLeft,
|
);
|
||||||
);
|
context.showAdaptiveMenu(
|
||||||
return null;
|
getEventOptions!(event).toList(),
|
||||||
},
|
globalPosition: topLeft,
|
||||||
),
|
);
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
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;
|
||||||
},
|
},
|
||||||
child: Container(
|
onPointerCancel: (_) => pointerDown.value = null,
|
||||||
decoration: BoxDecoration(
|
child: GestureDetector(
|
||||||
color: focusNode.hasPrimaryFocus
|
onSecondaryTapUp: contextMenuCallback,
|
||||||
? theme.colorScheme.surfaceContainerHighest
|
onLongPressStart: contextMenuCallback,
|
||||||
: null,
|
child: SwipeToReply(
|
||||||
),
|
onSwipe: onSwipe,
|
||||||
child: GestureDetector(
|
Padding(
|
||||||
onSecondaryTapUp: contextMenuCallback,
|
// Even on every side, so the highlight's centered. Lists
|
||||||
onLongPressStart: contextMenuCallback,
|
// add more space at their edges.
|
||||||
child: SwipeToReply(
|
padding: .symmetric(
|
||||||
onSwipe: onSwipe,
|
horizontal: 4,
|
||||||
Padding(
|
vertical: child is MessageRenderer ? 4 : 0,
|
||||||
padding: EdgeInsets.symmetric(horizontal: 8)
|
),
|
||||||
.copyWith(top: isGrouped ? 0 : 8),
|
child: Wrap(
|
||||||
child: Wrap(
|
verticalDirection: .up,
|
||||||
verticalDirection: .up,
|
spacing: 6,
|
||||||
spacing: 6,
|
crossAxisAlignment: .center,
|
||||||
crossAxisAlignment: .center,
|
children: [
|
||||||
children: [
|
child,
|
||||||
child,
|
if (child is! MessageRenderer &&
|
||||||
if (child is! MessageRenderer &&
|
child is! GenericEventRenderer)
|
||||||
child is! GenericEventRenderer)
|
Timestamp(event.timestamp),
|
||||||
Timestamp(event.timestamp),
|
],
|
||||||
],
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,10 @@ class const MessageRenderer(
|
||||||
final VoidCallback? onTapThread,
|
final VoidCallback? onTapThread,
|
||||||
final bool textOnly = false,
|
final bool textOnly = false,
|
||||||
final bool isGrouped = 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,
|
final int? maxLines,
|
||||||
super.key,
|
super.key,
|
||||||
}) extends HookConsumerWidget {
|
}) extends HookConsumerWidget {
|
||||||
|
|
@ -173,12 +177,11 @@ class const MessageRenderer(
|
||||||
children: [
|
children: [
|
||||||
if (!textOnly)
|
if (!textOnly)
|
||||||
if (isGrouped)
|
if (isGrouped)
|
||||||
// Shows when the message was sent on hover, as grouped messages
|
// When the message was sent, as grouped messages have no header
|
||||||
// have no header
|
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 40,
|
width: 40,
|
||||||
child: Visibility.maintain(
|
child: Visibility.maintain(
|
||||||
visible: hovered.value,
|
visible: hovered.value || showTime,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: .only(top: 14),
|
padding: .only(top: 14),
|
||||||
child: Tooltip(
|
child: Tooltip(
|
||||||
|
|
@ -213,7 +216,7 @@ class const MessageRenderer(
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Card(
|
Card(
|
||||||
margin: textOnly ? .zero : .only(bottom: 4),
|
margin: .zero,
|
||||||
color: textOnly
|
color: textOnly
|
||||||
? Colors.transparent
|
? Colors.transparent
|
||||||
: ref.watch(
|
: ref.watch(
|
||||||
|
|
|
||||||
|
|
@ -24,24 +24,28 @@ class const ChatTimeline({
|
||||||
int eventRowId,
|
int eventRowId,
|
||||||
int? previousEventRowId, {
|
int? previousEventRowId, {
|
||||||
required Key key,
|
required Key key,
|
||||||
}) => HighlightWrapper(
|
}) => Padding(
|
||||||
// To work around an AWFUL SuperSliverList bug
|
|
||||||
ConstrainedBox(
|
|
||||||
constraints: const BoxConstraints(minHeight: 0.01),
|
|
||||||
child: EventRenderer(
|
|
||||||
eventRowId,
|
|
||||||
previousEventRowId: previousEventRowId,
|
|
||||||
roomId: chat.roomId,
|
|
||||||
jumpToEvent: jumpToEvent,
|
|
||||||
onOpenThread: onOpenThread,
|
|
||||||
getEventOptions: getEventOptions,
|
|
||||||
onSwipe: onSwipe == null ? null : () => onSwipe!(eventRowId),
|
|
||||||
readReceiptsChat: chat,
|
|
||||||
threadRoot: chat.threadRoot,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
key: key,
|
key: key,
|
||||||
isHighlighted: scroll.highlightedEvent == eventRowId,
|
// 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),
|
||||||
|
child: EventRenderer(
|
||||||
|
eventRowId,
|
||||||
|
previousEventRowId: previousEventRowId,
|
||||||
|
roomId: chat.roomId,
|
||||||
|
jumpToEvent: jumpToEvent,
|
||||||
|
onOpenThread: onOpenThread,
|
||||||
|
getEventOptions: getEventOptions,
|
||||||
|
onSwipe: onSwipe == null ? null : () => onSwipe!(eventRowId),
|
||||||
|
readReceiptsChat: chat,
|
||||||
|
threadRoot: chat.threadRoot,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
isHighlighted: scroll.highlightedEvent == eventRowId,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ final class const PinnedEventsDrawer(
|
||||||
jumpToEvent(rowId);
|
jumpToEvent(rowId);
|
||||||
},
|
},
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: .symmetric(vertical: 4),
|
padding: .symmetric(vertical: 4, horizontal: 4),
|
||||||
child: IgnorePointer(
|
child: IgnorePointer(
|
||||||
child: EventRenderer(
|
child: EventRenderer(
|
||||||
rowId,
|
rowId,
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ final class const SearchDrawer(
|
||||||
jumpToEvent(rowId);
|
jumpToEvent(rowId);
|
||||||
},
|
},
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: .symmetric(vertical: 4),
|
padding: .symmetric(vertical: 4, horizontal: 4),
|
||||||
child: IgnorePointer(
|
child: IgnorePointer(
|
||||||
child: EventRenderer(
|
child: EventRenderer(
|
||||||
rowId,
|
rowId,
|
||||||
|
|
|
||||||
|
|
@ -170,8 +170,14 @@ class const NotificationsList({super.key})
|
||||||
|
|
||||||
await ref.focusRoom(roomId, rowId);
|
await ref.focusRoom(roomId, rowId);
|
||||||
},
|
},
|
||||||
child: IgnorePointer(
|
child: Padding(
|
||||||
child: EventRenderer(rowId, roomId: roomId),
|
padding: .symmetric(horizontal: 4),
|
||||||
|
child: IgnorePointer(
|
||||||
|
child: EventRenderer(
|
||||||
|
rowId,
|
||||||
|
roomId: roomId,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
isHighlighted: isHighlighted,
|
isHighlighted: isHighlighted,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue