#1100 viewer: dismiss feedback when opening popup menu

This commit is contained in:
Thibault Deckers 2024-07-26 22:20:53 +02:00
parent 2a91306532
commit 20ca48a5ed
6 changed files with 20 additions and 27 deletions

View file

@ -24,6 +24,7 @@ typedef MarginComputer = EdgeInsets Function(BuildContext context);
mixin FeedbackMixin {
static final ValueNotifier<MarginComputer?> snackBarMarginOverrideNotifier = ValueNotifier(null);
static OverlaySupportEntry? _overlayNotificationEntry;
static EdgeInsets snackBarMarginDefault(BuildContext context) {
return EdgeInsets.only(
@ -31,7 +32,11 @@ mixin FeedbackMixin {
);
}
void dismissFeedback(BuildContext context) => ScaffoldMessenger.of(context).hideCurrentSnackBar();
void dismissFeedback(BuildContext context) {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
_overlayNotificationEntry?.dismiss();
_overlayNotificationEntry = null;
}
void showFeedback(BuildContext context, FeedbackType type, String message, [SnackBarAction? action]) {
ScaffoldMessengerState? scaffoldMessenger;
@ -67,8 +72,7 @@ mixin FeedbackMixin {
// and space under the snack bar `margin` does not receive gestures
// (because it is used by the `Dismissible` wrapping the snack bar)
// so we use `showOverlayNotification` instead
OverlaySupportEntry? notificationOverlayEntry;
notificationOverlayEntry = showOverlayNotification(
_overlayNotificationEntry = showOverlayNotification(
(context) => SafeArea(
bottom: false,
child: ValueListenableBuilder<MarginComputer?>(
@ -89,7 +93,7 @@ mixin FeedbackMixin {
foregroundColor: WidgetStateProperty.all(snackBarTheme.actionTextColor),
),
onPressed: () {
notificationOverlayEntry?.dismiss();
dismissFeedback(context);
action.onPressed();
},
child: Text(action.label),
@ -97,7 +101,7 @@ mixin FeedbackMixin {
: null,
animation: kAlwaysCompleteAnimation,
dismissDirection: DismissDirection.horizontal,
onDismiss: () => notificationOverlayEntry?.dismiss(),
onDismiss: () => dismissFeedback(context),
),
),
),

View file

@ -126,3 +126,6 @@ class FullImageLoadedNotification extends Notification {
const FullImageLoadedNotification(this.entry, this.image);
}
@immutable
class PopupMenuOpenedNotification extends Notification {}

View file

@ -494,13 +494,6 @@ class _EntryViewerStackState extends State<EntryViewerStack> with EntryViewContr
);
}
},
onActionMenuOpened: () {
// if the menu is opened while overlay is hiding,
// the popup menu button is disposed and menu items are ineffective,
// so we make sure overlay stays visible
_videoActionDelegate.stopOverlayHidingTimer();
const ToggleOverlayNotification(visible: true).dispatch(context);
},
),
);
} else if (targetEntry.is360) {
@ -602,6 +595,13 @@ class _EntryViewerStackState extends State<EntryViewerStack> with EntryViewContr
case MoveType.export:
break;
}
} else if (notification is PopupMenuOpenedNotification) {
// if the menu is opened while overlay is hiding,
// the popup menu button is disposed and menu items are ineffective,
// so we make sure overlay stays visible
_overlayVisible.value = true;
_videoActionDelegate.stopOverlayHidingTimer();
dismissFeedback(context);
} else if (notification is ToggleOverlayNotification) {
_overlayVisible.value = notification.visible ?? !_overlayVisible.value;
} else if (notification is LockViewNotification) {

View file

@ -16,7 +16,6 @@ class VideoControlOverlay extends StatefulWidget {
final AvesVideoController? controller;
final Animation<double> scale;
final Function(EntryAction value) onActionSelected;
final VoidCallback onActionMenuOpened;
const VideoControlOverlay({
super.key,
@ -24,7 +23,6 @@ class VideoControlOverlay extends StatefulWidget {
required this.controller,
required this.scale,
required this.onActionSelected,
required this.onActionMenuOpened,
});
@override

View file

@ -315,12 +315,7 @@ class _ViewerButtonRowContentState extends State<ViewerButtonRowContent> {
_popupExpandedNotifier.value = null;
},
iconSize: IconTheme.of(context).size,
onMenuOpened: () {
// if the menu is opened while overlay is hiding,
// the popup menu button is disposed and menu items are ineffective,
// so we make sure overlay stays visible
const ToggleOverlayNotification(visible: true).dispatch(context);
},
onMenuOpened: () => PopupMenuOpenedNotification().dispatch(context),
popUpAnimationStyle: animations.popUpAnimationStyle,
),
),

View file

@ -187,13 +187,6 @@ class _EntryEditorState extends State<EntryEditor> with EntryViewControllerMixin
controller: videoController,
action: action,
),
onActionMenuOpened: () {
// if the menu is opened while overlay is hiding,
// the popup menu button is disposed and menu items are ineffective,
// so we make sure overlay stays visible
_videoActionDelegate.stopOverlayHidingTimer();
const ToggleOverlayNotification(visible: true).dispatch(context);
},
),
);
}