use a text span with a recognizer instead of a WidgetSpan
Fixes displaynames not ellipsising properly
This commit is contained in:
parent
1efbc131b4
commit
f971c50df0
4 changed files with 139 additions and 67 deletions
|
|
@ -12,4 +12,12 @@ extension GlobalRect on BuildContext {
|
|||
_ => Rect.zero,
|
||||
};
|
||||
}
|
||||
|
||||
/// [position] on screen as an empty rect, like where text was tapped, to
|
||||
/// open a popover there.
|
||||
Rect globalRectAt(Offset position) {
|
||||
final overlay = Overlay.of(this).context.findRenderObject() as RenderBox;
|
||||
|
||||
return overlay.globalToLocal(position) & .zero;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,20 +5,20 @@ import "package:nexus/helpers/extensions/show_adaptive_sheet.dart";
|
|||
import "package:nexus/widgets/popover_layout.dart";
|
||||
|
||||
extension ShowAdaptivePopover on BuildContext {
|
||||
/// Shows the widget from [builder] in a popover next to the widget this
|
||||
/// context belongs to on desktop, or a bottom sheet on mobile. Use the
|
||||
/// context passed to [builder] to close it.
|
||||
Future<void> showAdaptivePopover(WidgetBuilder builder) {
|
||||
/// Shows the widget from [builder] in a popover next to [anchor], or the
|
||||
/// widget this context belongs to, on desktop, or a bottom sheet on mobile.
|
||||
/// Use the context passed to [builder] to close it.
|
||||
Future<void> showAdaptivePopover(WidgetBuilder builder, {Rect? anchor}) {
|
||||
if (!isDesktop) return showAdaptiveSheet(builder);
|
||||
|
||||
final anchor = globalRect;
|
||||
final rect = anchor ?? globalRect;
|
||||
|
||||
return showDialog(
|
||||
context: this,
|
||||
barrierColor: Colors.transparent,
|
||||
useSafeArea: false,
|
||||
builder: (context) => CustomSingleChildLayout(
|
||||
delegate: PopoverLayout(anchor),
|
||||
delegate: PopoverLayout(rect),
|
||||
child: ConstrainedBox(
|
||||
constraints: const .new(maxWidth: 420, maxHeight: 600),
|
||||
child: Material(
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ import "package:nexus/helpers/extensions/show_adaptive_popover.dart";
|
|||
import "package:nexus/widgets/user_bottom_sheet.dart";
|
||||
|
||||
extension ShowUserPopover on BuildContext {
|
||||
void showUserPopover(String userId, {String? roomId}) =>
|
||||
showAdaptivePopover((context) => UserBottomSheet(userId, roomId: roomId));
|
||||
void showUserPopover(String userId, {String? roomId, Rect? anchor}) =>
|
||||
showAdaptivePopover(
|
||||
(context) => UserBottomSheet(userId, roomId: roomId),
|
||||
anchor: anchor,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
11
lib/helpers/hooks/tap_recognizer.dart
Normal file
11
lib/helpers/hooks/tap_recognizer.dart
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import "package:flutter/gestures.dart";
|
||||
import "package:flutter_hooks/flutter_hooks.dart";
|
||||
|
||||
/// A recognizer for a tappable span in text, like a name, disposed with the
|
||||
/// widget.
|
||||
TapGestureRecognizer useTapRecognizer() {
|
||||
final recognizer = useMemoized(TapGestureRecognizer.new);
|
||||
useEffect(() => recognizer.dispose, [recognizer]);
|
||||
|
||||
return recognizer;
|
||||
}
|
||||
Loading…
Reference in a new issue