Compare commits
16 changed files with 86 additions and 256 deletions
|
|
@ -11,8 +11,6 @@ import "package:nexus/controllers/rooms.dart";
|
|||
import "package:nexus/controllers/room_chat.dart";
|
||||
import "package:nexus/controllers/via.dart";
|
||||
import "package:nexus/helpers/extensions/event_id_is_fake.dart";
|
||||
import "package:nexus/helpers/extensions/is_desktop.dart";
|
||||
import "package:nexus/helpers/extensions/show_adaptive_sheet.dart";
|
||||
import "package:nexus/models/content/message.dart";
|
||||
import "package:nexus/models/event.dart";
|
||||
import "package:nexus/models/relation_type.dart";
|
||||
|
|
@ -29,7 +27,6 @@ extension BuildEventOptions on Event {
|
|||
}) {
|
||||
final theme = Theme.of(context);
|
||||
final danger = theme.colorScheme.error;
|
||||
final isDesktop = context.isDesktop;
|
||||
|
||||
final notifier = RoomChatController.provider((
|
||||
roomId: roomId,
|
||||
|
|
@ -99,7 +96,7 @@ extension BuildEventOptions on Event {
|
|||
child: IconTheme(
|
||||
data: theme.iconTheme,
|
||||
child: Row(
|
||||
mainAxisAlignment: isDesktop ? .center : .spaceEvenly,
|
||||
mainAxisAlignment: .center,
|
||||
children: [
|
||||
...{
|
||||
...ref
|
||||
|
|
@ -109,15 +106,11 @@ extension BuildEventOptions on Event {
|
|||
"🤣",
|
||||
"😭",
|
||||
"🤔",
|
||||
"❤️",
|
||||
}
|
||||
.take(isDesktop ? 3 : 5)
|
||||
.take(3)
|
||||
.map(
|
||||
(emoji) => IconButton(
|
||||
icon: Text(
|
||||
emoji,
|
||||
style: .new(fontSize: isDesktop ? null : 18),
|
||||
),
|
||||
icon: Text(emoji),
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
await ref
|
||||
|
|
@ -137,8 +130,10 @@ extension BuildEventOptions on Event {
|
|||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
context.showAdaptiveSheet(
|
||||
(context) => EmojiPicker(
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
builder: (context) => EmojiPicker(
|
||||
allowFreeText: true,
|
||||
onSelection: (emoji) {
|
||||
Navigator.of(context).pop();
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
|
||||
extension GlobalRect on BuildContext {
|
||||
/// Where the widget this context belongs to is on screen, e.g. to open a
|
||||
/// menu or popover next to it.
|
||||
Rect get globalRect {
|
||||
final overlay = Overlay.of(this).context.findRenderObject() as RenderBox;
|
||||
|
||||
return switch (findRenderObject()) {
|
||||
final RenderBox box =>
|
||||
box.localToGlobal(.zero, ancestor: overlay) & box.size,
|
||||
_ => Rect.zero,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
|
||||
extension IsDesktop on BuildContext {
|
||||
/// Whether the window is wide enough for the desktop layout, with the
|
||||
/// sidebar always visible, menus instead of bottom sheets, etc.
|
||||
bool get isDesktop => MediaQuery.sizeOf(this).width > 650;
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
import "package:nexus/helpers/extensions/global_rect.dart";
|
||||
import "package:nexus/helpers/extensions/is_desktop.dart";
|
||||
|
||||
extension ShowAdaptiveMenu on BuildContext {
|
||||
/// Shows [items] in a popup menu on desktop, or a bottom sheet on mobile.
|
||||
///
|
||||
/// On desktop, the menu opens at [globalPosition] if given (e.g. where the
|
||||
/// user right clicked), or over the widget this context belongs to.
|
||||
Future<void> showAdaptiveMenu(
|
||||
List<PopupMenuEntry> items, {
|
||||
Offset? globalPosition,
|
||||
}) async {
|
||||
if (!isDesktop) {
|
||||
await showModalBottomSheet(
|
||||
context: this,
|
||||
isScrollControlled: true,
|
||||
showDragHandle: true,
|
||||
builder: (context) => SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
padding: const .only(bottom: 8),
|
||||
// PopupMenuItems must be inside something with the menu role
|
||||
child: Semantics(
|
||||
role: .menu,
|
||||
explicitChildNodes: true,
|
||||
child: ListTileTheme.merge(
|
||||
contentPadding: const .symmetric(horizontal: 24),
|
||||
minTileHeight: 48,
|
||||
titleTextStyle: Theme.of(context).textTheme.titleMedium,
|
||||
child: Column(mainAxisSize: .min, children: items),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final overlay = Overlay.of(this).context.findRenderObject() as RenderBox;
|
||||
final anchor = switch (globalPosition) {
|
||||
final position? => position & Size.zero,
|
||||
null => globalRect,
|
||||
};
|
||||
|
||||
await showMenu(
|
||||
context: this,
|
||||
constraints: .loose(.infinite),
|
||||
position: .fromRect(anchor, Offset.zero & overlay.size),
|
||||
items: items,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
import "package:nexus/helpers/extensions/global_rect.dart";
|
||||
import "package:nexus/helpers/extensions/is_desktop.dart";
|
||||
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) {
|
||||
if (!isDesktop) return showAdaptiveSheet(builder);
|
||||
|
||||
final anchor = globalRect;
|
||||
|
||||
return showDialog(
|
||||
context: this,
|
||||
barrierColor: Colors.transparent,
|
||||
useSafeArea: false,
|
||||
builder: (context) => CustomSingleChildLayout(
|
||||
delegate: PopoverLayout(anchor),
|
||||
child: ConstrainedBox(
|
||||
constraints: const .new(maxWidth: 420, maxHeight: 600),
|
||||
child: Material(
|
||||
elevation: 8,
|
||||
clipBehavior: .antiAlias,
|
||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||
borderRadius: .circular(16),
|
||||
child: Builder(builder: builder),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
import "package:nexus/helpers/extensions/is_desktop.dart";
|
||||
|
||||
extension ShowAdaptiveSheet on BuildContext {
|
||||
/// Shows the widget from [builder] in a dialog on desktop, or a bottom sheet
|
||||
/// on mobile. Use the context passed to [builder] to close it.
|
||||
Future<void> showAdaptiveSheet(WidgetBuilder builder) => isDesktop
|
||||
? showDialog(
|
||||
context: this,
|
||||
builder: (context) => Dialog(
|
||||
clipBehavior: .antiAlias,
|
||||
child: ConstrainedBox(
|
||||
constraints: const .new(maxWidth: 450, maxHeight: 600),
|
||||
child: Builder(builder: builder),
|
||||
),
|
||||
),
|
||||
)
|
||||
: showModalBottomSheet(
|
||||
context: this,
|
||||
isScrollControlled: true,
|
||||
constraints: .new(maxHeight: MediaQuery.sizeOf(this).height - 80),
|
||||
builder: builder,
|
||||
);
|
||||
}
|
||||
22
lib/helpers/extensions/show_context_menu.dart
Normal file
22
lib/helpers/extensions/show_context_menu.dart
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
|
||||
extension ShowContextMenu on BuildContext {
|
||||
void showContextMenu({
|
||||
required Offset globalPosition,
|
||||
required List<PopupMenuEntry> children,
|
||||
}) {
|
||||
final overlay = Overlay.of(this).context.findRenderObject() as RenderBox;
|
||||
|
||||
showMenu(
|
||||
context: this,
|
||||
constraints: .loose(.infinite),
|
||||
position: .fromLTRB(
|
||||
globalPosition.dx,
|
||||
globalPosition.dy,
|
||||
overlay.size.width - globalPosition.dx,
|
||||
overlay.size.height - globalPosition.dy,
|
||||
),
|
||||
items: children,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
import "package:nexus/helpers/extensions/show_adaptive_popover.dart";
|
||||
import "package:nexus/models/content/membership.dart";
|
||||
import "package:nexus/widgets/user_bottom_sheet.dart";
|
||||
|
||||
|
|
@ -8,7 +7,12 @@ extension ShowUserPopover on BuildContext {
|
|||
MembershipContent member,
|
||||
String userId, {
|
||||
String? roomId,
|
||||
}) => showAdaptivePopover(
|
||||
(context) => UserBottomSheet(member, userId, roomId: roomId),
|
||||
}) => showModalBottomSheet(
|
||||
constraints: BoxConstraints.loose(
|
||||
Size(500, View.of(this).physicalSize.height - 80),
|
||||
),
|
||||
isScrollControlled: true,
|
||||
context: this,
|
||||
builder: (context) => UserBottomSheet(member, userId, roomId: roomId),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
import "package:nexus/helpers/extensions/show_adaptive_menu.dart";
|
||||
|
||||
/// Like [PopupMenuButton], but shows a bottom sheet on mobile.
|
||||
class const AdaptiveMenuButton({
|
||||
required final Widget icon,
|
||||
required final List<PopupMenuEntry> Function(BuildContext context)
|
||||
itemBuilder,
|
||||
final String? tooltip,
|
||||
final bool enabled = true,
|
||||
super.key,
|
||||
}) extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) => IconButton(
|
||||
icon: icon,
|
||||
tooltip: tooltip,
|
||||
onPressed: enabled
|
||||
? () => context.showAdaptiveMenu(itemBuilder(context))
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
|
@ -4,8 +4,6 @@ import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
|||
import "package:file_selector/file_selector.dart";
|
||||
import "package:nexus/controllers/rooms.dart";
|
||||
import "package:nexus/widgets/emoji_picker.dart";
|
||||
import "package:nexus/helpers/extensions/show_adaptive_sheet.dart";
|
||||
import "package:nexus/widgets/adaptive_menu_button.dart";
|
||||
import "package:material_ui/material_ui.dart";
|
||||
import "package:flutter/services.dart";
|
||||
import "package:flutter_hooks/flutter_hooks.dart";
|
||||
|
|
@ -167,8 +165,10 @@ class const Composer(
|
|||
)
|
||||
? [
|
||||
IconButton(
|
||||
onPressed: () => context.showAdaptiveSheet(
|
||||
(context) => EmojiPicker(
|
||||
onPressed: () => showModalBottomSheet(
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
builder: (context) => EmojiPicker(
|
||||
onSelection: (value) {
|
||||
Navigator.of(context).pop();
|
||||
controller.text += value;
|
||||
|
|
@ -178,7 +178,7 @@ class const Composer(
|
|||
),
|
||||
icon: Icon(Icons.emoji_emotions),
|
||||
),
|
||||
AdaptiveMenuButton(
|
||||
PopupMenuButton(
|
||||
tooltip: "Add media",
|
||||
enabled: attachment == null,
|
||||
itemBuilder: (context) => [
|
||||
|
|
|
|||
|
|
@ -106,16 +106,8 @@ class const MemberList(final String roomId, {super.key})
|
|||
MembershipContent(
|
||||
:final avatarUrl,
|
||||
:final displayName,
|
||||
) &&
|
||||
final content =>
|
||||
Builder(
|
||||
builder: (context) => ListTile(
|
||||
onTap: () =>
|
||||
context.showUserPopover(
|
||||
content,
|
||||
members[index].stateKey!,
|
||||
roomId: roomId,
|
||||
),
|
||||
) =>
|
||||
ListTile(
|
||||
title: Text(
|
||||
displayName ??
|
||||
members[index]
|
||||
|
|
@ -145,11 +137,21 @@ class const MemberList(final String roomId, {super.key})
|
|||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
_ => throw Exception(
|
||||
"Member content was not MembershipContent",
|
||||
),
|
||||
},
|
||||
onTap: (index) {
|
||||
final member = members[index];
|
||||
if (member.content
|
||||
case MembershipContent content) {
|
||||
context.showUserPopover(
|
||||
content,
|
||||
member.stateKey!,
|
||||
roomId: roomId,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
];
|
||||
}).toList(),
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import "package:hooks_riverpod/hooks_riverpod.dart";
|
|||
import "package:nexus/controllers/init_complete.dart";
|
||||
import "package:nexus/controllers/key.dart";
|
||||
import "package:nexus/controllers/notification_request.dart";
|
||||
import "package:nexus/helpers/extensions/is_desktop.dart";
|
||||
import "package:nexus/widgets/appbar.dart";
|
||||
import "package:nexus/widgets/sidebar.dart";
|
||||
import "package:nexus/widgets/sync_status_banner.dart";
|
||||
|
|
@ -35,7 +34,7 @@ class const ChatPage({super.key}) extends HookConsumerWidget {
|
|||
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final isDesktop = context.isDesktop;
|
||||
final isDesktop = constraints.maxWidth > 650;
|
||||
final showMembersByDefault = constraints.maxWidth > 1000;
|
||||
final roomId = ref
|
||||
.watch(KeyController.provider(KeyController.roomKey))
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
import "dart:math";
|
||||
|
||||
import "package:material_ui/material_ui.dart";
|
||||
|
||||
/// Positions a popover below [anchor], or above it if there isn't room below,
|
||||
/// keeping it fully on screen.
|
||||
class const PopoverLayout(final Rect anchor) extends SingleChildLayoutDelegate {
|
||||
static const margin = 8.0;
|
||||
|
||||
@override
|
||||
BoxConstraints getConstraintsForChild(BoxConstraints constraints) =>
|
||||
constraints.loosen().deflate(const .all(margin));
|
||||
|
||||
@override
|
||||
Offset getPositionForChild(Size size, Size childSize) {
|
||||
final fitsBelow = anchor.bottom + childSize.height + margin <= size.height;
|
||||
|
||||
return .new(
|
||||
anchor.left.clamp(
|
||||
margin,
|
||||
max(margin, size.width - childSize.width - margin),
|
||||
),
|
||||
(fitsBelow ? anchor.bottom : anchor.top - childSize.height).clamp(
|
||||
margin,
|
||||
max(margin, size.height - childSize.height - margin),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRelayout(PopoverLayout oldDelegate) =>
|
||||
oldDelegate.anchor != anchor;
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ import "package:hooks_riverpod/hooks_riverpod.dart";
|
|||
import "package:nexus/controllers/event.dart";
|
||||
import "package:nexus/controllers/room_chat.dart";
|
||||
import "package:nexus/controllers/rooms.dart";
|
||||
import "package:nexus/helpers/extensions/show_adaptive_menu.dart";
|
||||
import "package:nexus/helpers/extensions/show_context_menu.dart";
|
||||
import "package:nexus/helpers/hooks/chat_scroll.dart";
|
||||
import "package:nexus/models/content/avatar.dart";
|
||||
import "package:nexus/models/content/canonical_alias.dart";
|
||||
|
|
@ -197,9 +197,9 @@ class const EventRenderer(
|
|||
|
||||
final contextMenuCallback = getEventOptions == null
|
||||
? null
|
||||
: (PositionedGestureDetails details) => context.showAdaptiveMenu(
|
||||
getEventOptions!(event).toList(),
|
||||
: (PositionedGestureDetails details) => context.showContextMenu(
|
||||
globalPosition: details.globalPosition,
|
||||
children: getEventOptions!(event).toList(),
|
||||
);
|
||||
|
||||
return Column(
|
||||
|
|
@ -222,9 +222,9 @@ class const EventRenderer(
|
|||
final topLeft = renderBox.localToGlobal(
|
||||
Offset.zero,
|
||||
);
|
||||
context.showAdaptiveMenu(
|
||||
getEventOptions!(event).toList(),
|
||||
context.showContextMenu(
|
||||
globalPosition: topLeft,
|
||||
children: getEventOptions!(event).toList(),
|
||||
);
|
||||
return null;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import "package:material_ui/material_ui.dart";
|
|||
import "package:navigation_rail_m3e/navigation_rail_m3e.dart";
|
||||
import "package:nexus/helpers/extensions/get_all_child_rooms.dart";
|
||||
import "package:nexus/helpers/extensions/room_destinations.dart";
|
||||
import "package:nexus/widgets/adaptive_menu_button.dart";
|
||||
import "package:nexus/models/nav_page.dart";
|
||||
import "package:nexus/widgets/avatar_or_hash.dart";
|
||||
import "package:nexus/widgets/divider_widget.dart";
|
||||
|
|
@ -150,8 +149,7 @@ class const SpacesRail({super.key}) extends ConsumerWidget {
|
|||
padding: .only(top: 8),
|
||||
child: Column(
|
||||
children: [
|
||||
AdaptiveMenuButton(
|
||||
tooltip: "Add a room",
|
||||
PopupMenuButton(
|
||||
itemBuilder: (_) => [
|
||||
PopupMenuItem(
|
||||
onTap: () => showDialog(
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import "package:material_ui/material_ui.dart";
|
|||
import "package:flutter/services.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:nexus/controllers/client.dart";
|
||||
import "package:nexus/widgets/adaptive_menu_button.dart";
|
||||
import "package:nexus/controllers/via.dart";
|
||||
import "package:nexus/models/room.dart";
|
||||
import "package:flutter_hooks/flutter_hooks.dart";
|
||||
|
|
@ -19,9 +18,7 @@ final class const RoomMenuButton(
|
|||
final danger = Theme.of(context).colorScheme.error;
|
||||
final client = ref.read(ClientController.provider.notifier);
|
||||
|
||||
return AdaptiveMenuButton(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
tooltip: "Room options",
|
||||
return PopupMenuButton(
|
||||
itemBuilder: (_) => [
|
||||
PopupMenuItem(
|
||||
onTap: () async {
|
||||
|
|
|
|||
Loading…
Reference in a new issue