#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 { mixin FeedbackMixin {
static final ValueNotifier<MarginComputer?> snackBarMarginOverrideNotifier = ValueNotifier(null); static final ValueNotifier<MarginComputer?> snackBarMarginOverrideNotifier = ValueNotifier(null);
static OverlaySupportEntry? _overlayNotificationEntry;
static EdgeInsets snackBarMarginDefault(BuildContext context) { static EdgeInsets snackBarMarginDefault(BuildContext context) {
return EdgeInsets.only( 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]) { void showFeedback(BuildContext context, FeedbackType type, String message, [SnackBarAction? action]) {
ScaffoldMessengerState? scaffoldMessenger; ScaffoldMessengerState? scaffoldMessenger;
@ -67,8 +72,7 @@ mixin FeedbackMixin {
// and space under the snack bar `margin` does not receive gestures // and space under the snack bar `margin` does not receive gestures
// (because it is used by the `Dismissible` wrapping the snack bar) // (because it is used by the `Dismissible` wrapping the snack bar)
// so we use `showOverlayNotification` instead // so we use `showOverlayNotification` instead
OverlaySupportEntry? notificationOverlayEntry; _overlayNotificationEntry = showOverlayNotification(
notificationOverlayEntry = showOverlayNotification(
(context) => SafeArea( (context) => SafeArea(
bottom: false, bottom: false,
child: ValueListenableBuilder<MarginComputer?>( child: ValueListenableBuilder<MarginComputer?>(
@ -89,7 +93,7 @@ mixin FeedbackMixin {
foregroundColor: WidgetStateProperty.all(snackBarTheme.actionTextColor), foregroundColor: WidgetStateProperty.all(snackBarTheme.actionTextColor),
), ),
onPressed: () { onPressed: () {
notificationOverlayEntry?.dismiss(); dismissFeedback(context);
action.onPressed(); action.onPressed();
}, },
child: Text(action.label), child: Text(action.label),
@ -97,7 +101,7 @@ mixin FeedbackMixin {
: null, : null,
animation: kAlwaysCompleteAnimation, animation: kAlwaysCompleteAnimation,
dismissDirection: DismissDirection.horizontal, 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); 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) { } else if (targetEntry.is360) {
@ -602,6 +595,13 @@ class _EntryViewerStackState extends State<EntryViewerStack> with EntryViewContr
case MoveType.export: case MoveType.export:
break; 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) { } else if (notification is ToggleOverlayNotification) {
_overlayVisible.value = notification.visible ?? !_overlayVisible.value; _overlayVisible.value = notification.visible ?? !_overlayVisible.value;
} else if (notification is LockViewNotification) { } else if (notification is LockViewNotification) {

View file

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

View file

@ -315,12 +315,7 @@ class _ViewerButtonRowContentState extends State<ViewerButtonRowContent> {
_popupExpandedNotifier.value = null; _popupExpandedNotifier.value = null;
}, },
iconSize: IconTheme.of(context).size, iconSize: IconTheme.of(context).size,
onMenuOpened: () { onMenuOpened: () => PopupMenuOpenedNotification().dispatch(context),
// 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);
},
popUpAnimationStyle: animations.popUpAnimationStyle, popUpAnimationStyle: animations.popUpAnimationStyle,
), ),
), ),

View file

@ -187,13 +187,6 @@ class _EntryEditorState extends State<EntryEditor> with EntryViewControllerMixin
controller: videoController, controller: videoController,
action: action, 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);
},
), ),
); );
} }