From 390c485b6adfcc43d0c08a90562e8de36f9054fb Mon Sep 17 00:00:00 2001 From: HuyNguyen Date: Mon, 16 Dec 2024 14:53:14 +0700 Subject: [PATCH] TW-2098: Support enable/disable context menu Browser --- lib/pages/chat_list/chat_list.dart | 6 ++---- lib/widgets/mixins/twake_context_menu_mixin.dart | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index 1d222ed917..6f5ca7115c 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -35,7 +35,6 @@ import 'package:fluffychat/widgets/mixins/popup_menu_widget_mixin.dart'; import 'package:fluffychat/widgets/mixins/twake_context_menu_mixin.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_svg/svg.dart'; import 'package:go_router/go_router.dart'; @@ -534,6 +533,7 @@ class ChatListController extends State Room room, TapDownDetails details, ) async { + disableRightClick(); final offset = details.globalPosition; final listPopupActions = _popupMenuActions(room); final listContextActions = _mapPopupMenuActionsToContextMenuActions( @@ -546,6 +546,7 @@ class ChatListController extends State context: context, listActions: listContextActions, ); + enableRightClick(); if (selectedActionIndex != null && selectedActionIndex is int) { _handleClickOnContextMenuItem( listPopupActions[selectedActionIndex], @@ -774,9 +775,6 @@ class ChatListController extends State @override void initState() { - if (kIsWeb) { - BrowserContextMenu.disableContextMenu(); - } activeRoomIdNotifier.value = widget.activeRoomIdNotifier.value; scrollController.addListener(_onScroll); if (!matrixState.waitForFirstSync) { diff --git a/lib/widgets/mixins/twake_context_menu_mixin.dart b/lib/widgets/mixins/twake_context_menu_mixin.dart index 9333efb17d..5f29c00da0 100644 --- a/lib/widgets/mixins/twake_context_menu_mixin.dart +++ b/lib/widgets/mixins/twake_context_menu_mixin.dart @@ -1,9 +1,23 @@ import 'package:fluffychat/widgets/context_menu/context_menu_action.dart'; import 'package:fluffychat/widgets/context_menu/twake_context_menu.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; /// Show a [TwakeContextMenu] on the given [BuildContext]. For other parameters, see [TwakeContextMenu]. mixin TwakeContextMenuMixin { + void disableRightClick() { + if (kIsWeb) { + BrowserContextMenu.disableContextMenu(); + } + } + + void enableRightClick() { + if (kIsWeb) { + BrowserContextMenu.enableContextMenu(); + } + } + Future showTwakeContextMenu({ required List listActions, required Offset offset,