Skip to content

Commit 084ebfb

Browse files
wesbillmanCarl
andcommitted
Preserve message context in constrained action layouts
Keep the source message visible whenever the action popover cannot render its lifted preview, including short keyboard-safe viewports. Co-authored-by: Carl <c7ebe626f000404285d3686e1dc74cc07cc60a9754a150041ba132e14bd3e2ec@buzz.block.builderlab.xyz> Signed-off-by: Wes <[email protected]>
1 parent 019bff8 commit 084ebfb

5 files changed

Lines changed: 46 additions & 18 deletions

File tree

‎mobile/lib/features/channels/channel_detail_page/message_bubble.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class _MessageBubble extends HookConsumerWidget {
9090
isArchived: isArchived,
9191
anchorRect: details.anchorRect,
9292
captureAnchorSnapshot: details.captureSnapshot,
93-
onPopoverPresented: () => details.setSourceHidden(true),
93+
onPopoverPreviewVisibilityChanged: details.setSourceHidden,
9494
onPopoverDismissed: () => details.setSourceHidden(false),
9595
composerFocusNode: composerFocusNode,
9696
restoreComposerFocus: restoreComposerFocus,

‎mobile/lib/features/channels/message_actions.dart‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,10 @@ const _reminderPreviewLength = 100;
5252
///
5353
/// Popover capture is asynchronous: [captureAnchorSnapshot] must remain valid
5454
/// until its future completes, and the returned image becomes this function's
55-
/// responsibility to dispose. [onPopoverPresented] runs after capture succeeds
56-
/// and immediately before the route is pushed. [onPopoverDismissed] runs after
57-
/// that route completes while [context] is still mounted, so the callbacks are
58-
/// paired only while their owner remains mounted; neither runs for sheet
59-
/// fallback or a failed capture.
55+
/// responsibility to dispose. [onPopoverPreviewVisibilityChanged] reports
56+
/// whether the constrained layout actually renders the lifted preview;
57+
/// [onPopoverDismissed] runs after the route completes while [context] is still
58+
/// mounted. Neither callback runs for sheet fallback or a failed capture.
6059
///
6160
/// [composerFocusNode] remains caller-owned and must outlive the popover. If it
6261
/// has focus when this function is called, the popover unfocuses it and invokes
@@ -74,7 +73,7 @@ void showMessageActions({
7473
bool isMember = false,
7574
Rect? anchorRect,
7675
Future<ui.Image> Function()? captureAnchorSnapshot,
77-
VoidCallback? onPopoverPresented,
76+
ValueChanged<bool>? onPopoverPreviewVisibilityChanged,
7877
VoidCallback? onPopoverDismissed,
7978
FocusNode? composerFocusNode,
8079
VoidCallback? restoreComposerFocus,
@@ -105,7 +104,7 @@ void showMessageActions({
105104
isArchived: isArchived,
106105
anchorRect: anchorRect,
107106
captureAnchorSnapshot: captureAnchorSnapshot,
108-
onPopoverPresented: onPopoverPresented,
107+
onPopoverPreviewVisibilityChanged: onPopoverPreviewVisibilityChanged,
109108
onPopoverDismissed: onPopoverDismissed,
110109
composerFocusNode: composerFocusNode,
111110
restoreComposerFocus: restoreComposerFocus,

‎mobile/lib/features/channels/message_actions/message_action_popover.dart‎

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ bool _tryShowMessageActionsPopover({
5252
required bool isArchived,
5353
required Rect? anchorRect,
5454
required Future<ui.Image> Function()? captureAnchorSnapshot,
55-
required VoidCallback? onPopoverPresented,
55+
required ValueChanged<bool>? onPopoverPreviewVisibilityChanged,
5656
required VoidCallback? onPopoverDismissed,
5757
required FocusNode? composerFocusNode,
5858
required VoidCallback? restoreComposerFocus,
@@ -72,7 +72,7 @@ bool _tryShowMessageActionsPopover({
7272
isArchived: isArchived,
7373
anchorRect: anchorRect,
7474
captureAnchorSnapshot: captureAnchorSnapshot,
75-
onPopoverPresented: onPopoverPresented,
75+
onPopoverPreviewVisibilityChanged: onPopoverPreviewVisibilityChanged,
7676
onPopoverDismissed: onPopoverDismissed,
7777
composerFocusNode: composerFocusNode,
7878
restoreComposerFocus: restoreComposerFocus,
@@ -107,7 +107,7 @@ Future<bool> _showMessageActionsPopover({
107107
required bool isArchived,
108108
required Rect anchorRect,
109109
required Future<ui.Image> Function() captureAnchorSnapshot,
110-
required VoidCallback? onPopoverPresented,
110+
required ValueChanged<bool>? onPopoverPreviewVisibilityChanged,
111111
required VoidCallback? onPopoverDismissed,
112112
required FocusNode? composerFocusNode,
113113
required VoidCallback? restoreComposerFocus,
@@ -151,7 +151,6 @@ Future<bool> _showMessageActionsPopover({
151151
}
152152

153153
final reduceMotion = MediaQuery.disableAnimationsOf(context);
154-
onPopoverPresented?.call();
155154
if (shouldRestoreComposerFocus) composerFocusNode!.unfocus();
156155

157156
String? selectedActionId;
@@ -176,6 +175,7 @@ Future<bool> _showMessageActionsPopover({
176175
pageRef: ref,
177176
actions: actions,
178177
useIosNativeActionSurface: useIosNativeActionSurface,
178+
onPreviewVisibilityChanged: onPopoverPreviewVisibilityChanged,
179179
),
180180
);
181181
var routePushed = false;
@@ -505,6 +505,7 @@ class _MessageActionsPopover extends HookWidget {
505505
final WidgetRef pageRef;
506506
final List<_PopoverMessageAction> actions;
507507
final bool useIosNativeActionSurface;
508+
final ValueChanged<bool>? onPreviewVisibilityChanged;
508509

509510
const _MessageActionsPopover({
510511
required this.anchorRect,
@@ -515,6 +516,7 @@ class _MessageActionsPopover extends HookWidget {
515516
required this.pageRef,
516517
required this.actions,
517518
required this.useIosNativeActionSurface,
519+
required this.onPreviewVisibilityChanged,
518520
});
519521

520522
@override
@@ -633,8 +635,11 @@ class _MessageActionsPopover extends HookWidget {
633635
menuHeight,
634636
);
635637

636-
return Stack(
637-
children: [
638+
return _MessageActionPreviewVisibility(
639+
visible: showPreview,
640+
onChanged: onPreviewVisibilityChanged,
641+
child: Stack(
642+
children: [
638643
Positioned.fill(
639644
child: BackdropFilter(
640645
filter: ui.ImageFilter.blur(
@@ -764,13 +769,35 @@ class _MessageActionsPopover extends HookWidget {
764769
},
765770
),
766771
),
767-
],
772+
],
773+
),
768774
);
769775
},
770776
);
771777
}
772778
}
773779

780+
class _MessageActionPreviewVisibility extends HookWidget {
781+
final bool visible;
782+
final ValueChanged<bool>? onChanged;
783+
final Widget child;
784+
const _MessageActionPreviewVisibility({
785+
required this.visible,
786+
required this.onChanged,
787+
required this.child,
788+
});
789+
@override
790+
Widget build(BuildContext context) {
791+
useEffect(() {
792+
WidgetsBinding.instance.addPostFrameCallback((_) {
793+
if (context.mounted) onChanged?.call(visible);
794+
});
795+
return null;
796+
}, [visible, onChanged]);
797+
return child;
798+
}
799+
}
800+
774801
class _LiftedMessagePreview extends StatelessWidget {
775802
final ui.Image anchorSnapshot;
776803

‎mobile/lib/features/channels/thread_detail_page/thread_message.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class _ThreadMessage extends HookConsumerWidget {
8585
isArchived: isArchived,
8686
anchorRect: details.anchorRect,
8787
captureAnchorSnapshot: details.captureSnapshot,
88-
onPopoverPresented: () => details.setSourceHidden(true),
88+
onPopoverPreviewVisibilityChanged: details.setSourceHidden,
8989
onPopoverDismissed: () => details.setSourceHidden(false),
9090
composerFocusNode: composerFocusNode,
9191
restoreComposerFocus: restoreComposerFocus,

‎mobile/test/features/channels/message_actions_test.dart‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ Future<_MessageActionsPopoverHarness> _pumpMessageActionsPopover(
246246
anchorRect: anchorRect,
247247
captureAnchorSnapshot:
248248
captureAnchorSnapshot ?? _testMessageSnapshot,
249-
onPopoverPresented: () => sourceHidden.value = true,
249+
onPopoverPreviewVisibilityChanged: (visible) =>
250+
sourceHidden.value = visible,
250251
onPopoverDismissed: () => sourceHidden.value = false,
251252
composerFocusNode: composerFocusNode,
252253
restoreComposerFocus: composerFocusNode?.requestFocus,
@@ -704,7 +705,7 @@ void main() {
704705
addTearDown(tester.view.resetPhysicalSize);
705706
const keyboardInset = 100.0;
706707
final prefs = await _mockPrefs();
707-
await _pumpMessageActionsPopover(
708+
final harness = await _pumpMessageActionsPopover(
708709
tester,
709710
message: _message(),
710711
prefs: prefs,
@@ -721,6 +722,7 @@ void main() {
721722
find.byKey(const ValueKey('message-action-preview')),
722723
findsNothing,
723724
);
725+
expect(harness.sourceHidden.value, isFalse);
724726
final actionRect = tester.getRect(
725727
find.byKey(const ValueKey('message-action-surface')),
726728
);

0 commit comments

Comments
 (0)