Skip to content

Commit

Permalink
TW-2098: Support enable/disable context menu Browser
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Dec 16, 2024
1 parent 4dd46da commit 390c485
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/pages/chat_list/chat_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -534,6 +533,7 @@ class ChatListController extends State<ChatList>
Room room,
TapDownDetails details,
) async {
disableRightClick();
final offset = details.globalPosition;
final listPopupActions = _popupMenuActions(room);
final listContextActions = _mapPopupMenuActionsToContextMenuActions(
Expand All @@ -546,6 +546,7 @@ class ChatListController extends State<ChatList>
context: context,
listActions: listContextActions,
);
enableRightClick();
if (selectedActionIndex != null && selectedActionIndex is int) {
_handleClickOnContextMenuItem(
listPopupActions[selectedActionIndex],
Expand Down Expand Up @@ -774,9 +775,6 @@ class ChatListController extends State<ChatList>

@override
void initState() {
if (kIsWeb) {
BrowserContextMenu.disableContextMenu();
}
activeRoomIdNotifier.value = widget.activeRoomIdNotifier.value;
scrollController.addListener(_onScroll);
if (!matrixState.waitForFirstSync) {
Expand Down
14 changes: 14 additions & 0 deletions lib/widgets/mixins/twake_context_menu_mixin.dart
Original file line number Diff line number Diff line change
@@ -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<dynamic> showTwakeContextMenu({
required List<ContextMenuAction> listActions,
required Offset offset,
Expand Down

0 comments on commit 390c485

Please sign in to comment.