Skip to content

Commit 4ee9f8b

Browse files
authored
fix(mobile): keep iOS message menu actions responsive after rebuilds (#7758)
Long-pressing a message while the keyboard dismissed could leave the iOS action menu visible but unresponsive. Rebuilds installed a new selection handler before the previous hook's cleanup removed it. Keep that handler for the native view's lifetime and dispatch to the latest callback. Also let taps on decorative action icons reach the row control. Added regression coverage for callback rebuilds, view replacement/dismissal, and native icon/label/edge hit targets. The callback regression fails before the fix and passes after it. Validation: all 2,257 mobile tests (4 skipped), three unconfigured-push tests, mobile analysis, 42 focused action/handler tests, and three native XCTest checks passed. Physical iOS 26.5 taps verified keyboard-open long press, Edit, Copy (including clipboard contents), repeated opening, and outside dismissal. Desktop tests/builds, Tauri checks/tests, and the web build passed. The full local gate encountered unrelated Rust agent timeout failures; all 105 tests in the affected ACP test module passed when rerun serially. GitHub CI passed, including mobile tests, Swift tests, Android build, and iOS simulator/release builds. Codex code review completed without findings. No matching open issue or PR found. ### Before Synthetic message using the production long-press/menu components: Edit and Copy taps leave the menu open; tapping outside still dismisses it. https://github.com/user-attachments/assets/5e062d38-cbca-4be2-98b5-ca9a47b89df3 ### After With the keyboard open, the first Edit icon tap opens the editor. Reopening and tapping Copy copies the message and dismisses the menu. https://github.com/user-attachments/assets/49e11bfd-d531-4fa1-b551-5abd4fec83d7 Signed-off-by: Tom Brow <[email protected]>
1 parent 5511b56 commit 4ee9f8b

6 files changed

Lines changed: 124 additions & 11 deletions

File tree

‎mobile/ios/Runner/NativeMessageActionSurface.swift‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ final class NativeMessageActionRowControl: UIControl {
157157
)
158158

159159
let iconColumn = UIView()
160+
// Decorative content must leave the entire row tappable.
161+
iconColumn.isUserInteractionEnabled = false
160162
iconColumn.translatesAutoresizingMaskIntoConstraints = false
161163
actionImageView.translatesAutoresizingMaskIntoConstraints = false
162164
actionTitleLabel.translatesAutoresizingMaskIntoConstraints = false

‎mobile/ios/RunnerTests/RunnerTests.swift‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,42 @@ class RunnerTests: XCTestCase {
904904
XCTAssertTrue(selected)
905905
}
906906

907+
@MainActor
908+
func testNativeMessageActionRowReceivesTapsAcrossItsWholeSurface() throws {
909+
let definition = try XCTUnwrap(
910+
NativeMessageActionDefinition(
911+
arguments: [
912+
"id": "edit", "title": "Edit message",
913+
"symbol": "pencil", "group": "primary",
914+
]
915+
)
916+
)
917+
var selectionCount = 0
918+
let row = NativeMessageActionRowControl(
919+
definition: definition,
920+
foregroundColor: .label,
921+
destructiveColor: .systemRed,
922+
onSelected: { selectionCount += 1 }
923+
)
924+
row.frame = CGRect(x: 0, y: 0, width: 288, height: 48)
925+
row.layoutIfNeeded()
926+
927+
let iconCenter = row.actionImageView.convert(
928+
CGPoint(x: row.actionImageView.bounds.midX, y: row.actionImageView.bounds.midY),
929+
to: row
930+
)
931+
let labelCenter = row.actionTitleLabel.convert(
932+
CGPoint(x: row.actionTitleLabel.bounds.midX, y: row.actionTitleLabel.bounds.midY),
933+
to: row
934+
)
935+
for point in [CGPoint(x: 4, y: 24), iconCenter, labelCenter, CGPoint(x: 284, y: 24)] {
936+
let target = row.hitTest(point, with: nil)
937+
XCTAssertTrue(target === row, "Tap at \(point) must reach the action control")
938+
(target as? UIControl)?.sendActions(for: .touchUpInside)
939+
}
940+
XCTAssertEqual(selectionCount, 4)
941+
}
942+
907943
@MainActor
908944
func testNativeMessageActionRowExpandsForAccessibilityTypography() throws {
909945
let traits = UITraitCollection(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import '../../shared/reminders/reminder_service.dart';
3030
import 'channel_management_provider.dart';
3131
import 'emoji_picker.dart';
3232
import 'message_action_backdrop_state.dart';
33+
import 'message_actions/native_message_action_selection.dart';
3334
import 'reaction_row.dart';
3435
import 'recent_emoji_provider.dart';
3536
import '../../shared/read_state/message_read_state.dart';

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -477,17 +477,7 @@ class _IosNativeMessageActionSurface extends HookWidget {
477477
@override
478478
Widget build(BuildContext context) {
479479
final viewId = useState<int?>(null);
480-
useEffect(() {
481-
final id = viewId.value;
482-
if (id == null) return null;
483-
final channel = MethodChannel('buzz/native_message_action_surface/$id');
484-
channel.setMethodCallHandler((call) async {
485-
if (call.method != 'selected' || call.arguments is! Map) return;
486-
final actionId = (call.arguments as Map)['id'];
487-
if (actionId is String) onSelected(actionId);
488-
});
489-
return () => channel.setMethodCallHandler(null);
490-
}, [viewId.value, onSelected]);
480+
useNativeMessageActionSelection(viewId.value, onSelected);
491481

492482
return UiKitView(
493483
key: const ValueKey('ios-native-message-action-surface'),
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import 'package:flutter/services.dart';
2+
import 'package:flutter_hooks/flutter_hooks.dart';
3+
4+
/// Receives selections from the native message menu while [viewId] is mounted.
5+
void useNativeMessageActionSelection(
6+
int? viewId,
7+
ValueChanged<String> onSelected,
8+
) {
9+
final latestOnSelected = useRef(onSelected);
10+
latestOnSelected.value = onSelected;
11+
12+
// Callback changes must not replace this effect: the previous hook's cleanup
13+
// can clear the new handler on the same channel after a keyboard-driven rebuild.
14+
useEffect(() {
15+
if (viewId == null) return null;
16+
final channel = MethodChannel('buzz/native_message_action_surface/$viewId');
17+
channel.setMethodCallHandler((call) async {
18+
if (call.method != 'selected' || call.arguments is! Map) return;
19+
final actionId = (call.arguments as Map)['id'];
20+
if (actionId is String) latestOnSelected.value(actionId);
21+
});
22+
return () => channel.setMethodCallHandler(null);
23+
}, [viewId]);
24+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import 'package:buzz/features/channels/message_actions/native_message_action_selection.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:flutter/services.dart';
4+
import 'package:flutter_hooks/flutter_hooks.dart';
5+
import 'package:flutter_test/flutter_test.dart';
6+
7+
Future<void> _select(WidgetTester tester, int viewId, String action) async {
8+
tester.binding.channelBuffers.push(
9+
'buzz/native_message_action_surface/$viewId',
10+
const StandardMethodCodec().encodeMethodCall(
11+
MethodCall('selected', {'id': action}),
12+
),
13+
(_) {},
14+
);
15+
await tester.pump();
16+
}
17+
18+
Widget _menu(int? viewId, ValueChanged<String> onSelected) => HookBuilder(
19+
builder: (_) {
20+
useNativeMessageActionSelection(viewId, onSelected);
21+
return const SizedBox();
22+
},
23+
);
24+
25+
void main() {
26+
testWidgets('keeps native selections connected through callback rebuilds', (
27+
tester,
28+
) async {
29+
final selections = <String>[];
30+
await tester.pumpWidget(_menu(null, (id) => selections.add('initial:$id')));
31+
await tester.pumpWidget(_menu(41, (id) => selections.add('created:$id')));
32+
await _select(tester, 41, 'copyText');
33+
expect(selections, ['created:copyText']);
34+
35+
// Keyboard inset changes rebuild the popover with a fresh callback.
36+
for (var frame = 0; frame < 5; frame++) {
37+
await tester.pumpWidget(
38+
_menu(41, (id) => selections.add('frame$frame:$id')),
39+
);
40+
}
41+
await _select(tester, 41, 'edit');
42+
expect(selections, ['created:copyText', 'frame4:edit']);
43+
});
44+
45+
testWidgets('moves the handler to a new view and removes it on dismissal', (
46+
tester,
47+
) async {
48+
final selections = <String>[];
49+
await tester.pumpWidget(_menu(51, selections.add));
50+
await _select(tester, 51, 'copyText');
51+
await tester.pumpWidget(_menu(52, selections.add));
52+
await _select(tester, 51, 'edit');
53+
await _select(tester, 52, 'delete');
54+
expect(selections, ['copyText', 'delete']);
55+
56+
await tester.pumpWidget(const SizedBox());
57+
await _select(tester, 52, 'edit');
58+
expect(selections, ['copyText', 'delete']);
59+
});
60+
}

0 commit comments

Comments
 (0)