From 4d96a15c313d1074ff2f5439c811d29a0cb5fd56 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 24 Dec 2024 23:07:47 +0800 Subject: [PATCH] :bug: Fix context menu mis placed on device which showing the side navigation --- ios/Podfile.lock | 4 +- lib/widgets/chat/chat_message.dart | 3 +- lib/widgets/context_menu.dart | 47 ++++ lib/widgets/post/post_media_pending_list.dart | 11 +- pubspec.lock | 16 +- pubspec.yaml | 2 +- web/index.html | 221 +++++++++--------- 7 files changed, 178 insertions(+), 126 deletions(-) create mode 100644 lib/widgets/context_menu.dart diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 3e0161b..b4d56d6 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -173,7 +173,7 @@ PODS: - in_app_review (2.0.0): - Flutter - Kingfisher (8.1.3) - - livekit_client (2.3.2): + - livekit_client (2.3.3): - Flutter - flutter_webrtc - WebRTC-SDK (= 125.6422.06) @@ -386,7 +386,7 @@ SPEC CHECKSUMS: image_picker_ios: c560581cceedb403a6ff17f2f816d7fea1421fc1 in_app_review: a31b5257259646ea78e0e35fc914979b0031d011 Kingfisher: f2af9028b16baf9dc6c07c570072bc41cbf009ef - livekit_client: 6108dad8b77db3142bafd4c630f471d0a54335cd + livekit_client: 02cf2cc4357a655af12ccee70ff5596ae4e6feef media_kit_libs_ios_video: a5fe24bc7875ccd6378a0978c13185e1344651c1 media_kit_native_event_loop: e6b2ab20cf0746eb1c33be961fcf79667304fa2a media_kit_video: 5da63f157170e5bf303bf85453b7ef6971218a2e diff --git a/lib/widgets/chat/chat_message.dart b/lib/widgets/chat/chat_message.dart index 8c46383..4bde90d 100644 --- a/lib/widgets/chat/chat_message.dart +++ b/lib/widgets/chat/chat_message.dart @@ -10,6 +10,7 @@ import 'package:surface/providers/userinfo.dart'; import 'package:surface/types/chat.dart'; import 'package:surface/widgets/account/account_image.dart'; import 'package:surface/widgets/attachment/attachment_list.dart'; +import 'package:surface/widgets/context_menu.dart'; import 'package:surface/widgets/link_preview.dart'; import 'package:surface/widgets/markdown_content.dart'; import 'package:swipe_to/swipe_to.dart'; @@ -53,7 +54,7 @@ class ChatMessage extends StatelessWidget { swipeSensitivity: 20, onLeftSwipe: onReply != null ? (_) => onReply!(data) : null, onRightSwipe: onEdit != null ? (_) => onEdit!(data) : null, - child: ContextMenuRegion( + child: ContextMenuArea( contextMenu: ContextMenu( entries: [ MenuHeader(text: "eventResourceTag".tr(args: ['#${data.id}'])), diff --git a/lib/widgets/context_menu.dart b/lib/widgets/context_menu.dart new file mode 100644 index 0000000..2b705e1 --- /dev/null +++ b/lib/widgets/context_menu.dart @@ -0,0 +1,47 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_animate/flutter_animate.dart'; +import 'package:flutter_context_menu/flutter_context_menu.dart'; +import 'package:responsive_framework/responsive_framework.dart'; + +class ContextMenuArea extends StatelessWidget { + final ContextMenu contextMenu; + final Widget child; + final ValueChanged? onItemSelected; + + const ContextMenuArea({ + super.key, + required this.contextMenu, + required this.child, + this.onItemSelected, + }); + + @override + Widget build(BuildContext context) { + Offset mousePosition = Offset.zero; + + return Listener( + onPointerDown: (event) { + mousePosition = event.position; + final isCollapseDrawer = ResponsiveBreakpoints.of(context).smallerOrEqualTo(MOBILE); + if (!isCollapseDrawer) { + final isExpandDrawer = ResponsiveBreakpoints.of(context).largerThan(TABLET); + // Leave padding for side navigation + mousePosition = isExpandDrawer + ? mousePosition.copyWith(dx: mousePosition.dx - 304 * 2) + : mousePosition.copyWith(dx: mousePosition.dx - 72 * 2); + } + }, + child: GestureDetector( + onLongPress: () => _showMenu(context, mousePosition), + onSecondaryTap: () => _showMenu(context, mousePosition), + child: child, + ), + ); + } + + void _showMenu(BuildContext context, Offset mousePosition) async { + final menu = contextMenu.copyWith(position: contextMenu.position ?? mousePosition); + final value = await showContextMenu(context, contextMenu: menu); + onItemSelected?.call(value); + } +} diff --git a/lib/widgets/post/post_media_pending_list.dart b/lib/widgets/post/post_media_pending_list.dart index 9186e23..317529c 100644 --- a/lib/widgets/post/post_media_pending_list.dart +++ b/lib/widgets/post/post_media_pending_list.dart @@ -14,6 +14,7 @@ import 'package:styled_widget/styled_widget.dart'; import 'package:surface/controllers/post_write_controller.dart'; import 'package:surface/providers/sn_network.dart'; import 'package:surface/widgets/attachment/attachment_zoom.dart'; +import 'package:surface/widgets/context_menu.dart'; import 'package:surface/widgets/dialog.dart'; class PostMediaPendingList extends StatelessWidget { @@ -87,7 +88,7 @@ class PostMediaPendingList extends StatelessWidget { } } - ContextMenu _buildContextMenu(BuildContext context, int idx, PostWriteMedia media) { + ContextMenu _createContextMenu(BuildContext context, int idx, PostWriteMedia media) { return ContextMenu( entries: [ if (media.attachment == null && onUpload != null) @@ -174,8 +175,8 @@ class PostMediaPendingList extends StatelessWidget { children: [ const Gap(8), if (thumbnail != null) - ContextMenuRegion( - contextMenu: _buildContextMenu(context, -1, thumbnail!), + ContextMenuArea( + contextMenu: _createContextMenu(context, -1, thumbnail!), child: Container( decoration: BoxDecoration( border: Border.all( @@ -224,8 +225,8 @@ class PostMediaPendingList extends StatelessWidget { itemCount: attachments.length, itemBuilder: (context, idx) { final media = attachments[idx]; - return ContextMenuRegion( - contextMenu: _buildContextMenu(context, idx, media), + return ContextMenuArea( + contextMenu: _createContextMenu(context, idx, media), child: Container( decoration: BoxDecoration( border: Border.all( diff --git a/pubspec.lock b/pubspec.lock index 6da9693..6de3260 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -753,10 +753,10 @@ packages: dependency: "direct main" description: name: flutter_udid - sha256: be464dc5b1fb7ee894f6a32d65c086ca5e177fdcf9375ac08d77495b98150f84 + sha256: "166bee5989a58c66b8b62000ea65edccc7c8167bbafdbb08022638db330dd030" url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "4.0.0" flutter_web_plugins: dependency: "direct main" description: flutter @@ -766,10 +766,10 @@ packages: dependency: transitive description: name: flutter_webrtc - sha256: "430859fb5b763d7556d06ef287cfca582e17d9a2dc36da26017f25a5c0b2523e" + sha256: "0e138a0a3bf6830c29c8439b17be0e222d0de27fa72f24e6aee4d34de72f22ef" url: "https://pub.dev" source: hosted - version: "0.12.4" + version: "0.12.5" freezed: dependency: "direct dev" description: @@ -934,10 +934,10 @@ packages: dependency: transitive description: name: image_picker_android - sha256: fa8141602fde3f7e2f81dbf043613eb44dfa325fa0bcf93c0f142c9f7a2c193e + sha256: aa6f1280b670861ac45220cc95adc59bb6ae130259d36f980ccb62220dc5e59f url: "https://pub.dev" source: hosted - version: "0.8.12+18" + version: "0.8.12+19" image_picker_for_web: dependency: transitive description: @@ -1086,10 +1086,10 @@ packages: dependency: "direct main" description: name: livekit_client - sha256: "7802b5de1cae2ee3439db730d24d31c6dcbce173c5e6db2fc5774039a290bc2d" + sha256: a3ff529fe6745ee40cdedcd021d81c4a6ad946dd495e782596f2856eeeabc739 url: "https://pub.dev" source: hosted - version: "2.3.2" + version: "2.3.3" logging: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index b8856e1..5bfd01d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -80,7 +80,7 @@ dependencies: firebase_core: ^3.8.0 firebase_messaging: ^15.1.5 firebase_analytics: ^11.3.5 - flutter_udid: ^3.0.0 + flutter_udid: ^4.0.0 media_kit: ^1.1.11 media_kit_video: ^1.2.5 media_kit_libs_video: ^1.0.5 diff --git a/web/index.html b/web/index.html index 07de1cf..1734104 100644 --- a/web/index.html +++ b/web/index.html @@ -1,130 +1,133 @@ - - - + This is a placeholder for base href that will be replaced by the value of + the `--base-href` argument provided to `flutter build`. + --> + - - - + + + - - - - - + + + + + - - + + - Solian - - - - - - - - - - + .cover { + display:block; + width:100%; height:100%; + object-fit: cover; + } + + .bottom { + position: absolute; + bottom: 0; + left: 50%; + -ms-transform: translate(-50%, 0); + transform: translate(-50%, 0); + } + + .bottomLeft { + position: absolute; + bottom: 0; + left: 0; + } + + .bottomRight { + position: absolute; + bottom: 0; + right: 0; + } + + @media (prefers-color-scheme: dark) { + body { + background-color: #000000; + } + } + + - - - + + + - - - - - - - - - - - - + + + + + + - \ No newline at end of file + + + + + \ No newline at end of file