Skip to content

Commit 572b1c2

Browse files
msglist: Fix channel header tap behaviour in multi-channel narrows
Set gesture detecter behavior of streamWidget to HitTestBehavior.opaque to handle taps in empty space around the header. Fixes #1179.
1 parent 6bbe74f commit 572b1c2

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

lib/widgets/message_list.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,7 @@ class StreamMessageRecipientHeader extends StatelessWidget {
10821082
?? zulipLocalizations.unknownChannelName; // TODO(log)
10831083

10841084
streamWidget = GestureDetector(
1085+
behavior: HitTestBehavior.opaque,
10851086
onTap: () => Navigator.push(context,
10861087
MessageListPage.buildRoute(context: context,
10871088
narrow: ChannelNarrow(message.streamId))),

test/widgets/message_list_test.dart

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,4 +1470,107 @@ void main() {
14701470
..status.equals(AnimationStatus.dismissed);
14711471
});
14721472
});
1473+
1474+
group('recipient header navigation in multi-channel narrows', () {
1475+
late List<Route<void>> pushedRoutes;
1476+
1477+
final channel = eg.stream();
1478+
const testTopic = 'testTopic';
1479+
final message = eg.streamMessage(stream: channel, topic: testTopic);
1480+
1481+
final recipientHeaderFinder = find.byType(StreamMessageRecipientHeader);
1482+
late Rect recipientHeaderRect;
1483+
1484+
Future<void> prepare(WidgetTester tester) async {
1485+
pushedRoutes = [];
1486+
final navObserver = TestNavigatorObserver()
1487+
..onPushed = (route, prevRoute) => pushedRoutes.add(route);
1488+
1489+
await setupMessageListPage(tester,
1490+
narrow: const CombinedFeedNarrow(),
1491+
streams: [channel],
1492+
subscriptions: [eg.subscription(channel)],
1493+
messages: [message],
1494+
navObservers: [navObserver]);
1495+
1496+
assert(pushedRoutes.length == 1);
1497+
pushedRoutes.clear();
1498+
1499+
recipientHeaderRect = tester.getRect(recipientHeaderFinder);
1500+
}
1501+
1502+
// Regression test for: https://github.com/zulip/zulip-flutter/issues/1179
1503+
testWidgets("navigates to ChannelNarrow when tapping above or below channel name in recipient header", (tester) async {
1504+
await prepare(tester);
1505+
1506+
final channelNameFinder = find.descendant(
1507+
of: recipientHeaderFinder,
1508+
matching: find.text(channel.name));
1509+
final channelNameRect = tester.getRect(channelNameFinder);
1510+
1511+
connection.prepare(json: eg.newestGetMessagesResult(
1512+
foundOldest: true, messages: [message]).toJson());
1513+
// Tap just right below the top of recipient header, above and outside of
1514+
// its channel name component.
1515+
await tester.tapAt(Offset(
1516+
channelNameRect.center.dx, recipientHeaderRect.top + 1));
1517+
await tester.pump();
1518+
check(pushedRoutes).single.isA<WidgetRoute>().page.isA<MessageListPage>()
1519+
.initNarrow.equals(ChannelNarrow(channel.streamId));
1520+
await tester.pumpAndSettle();
1521+
1522+
// Navigate back to original page and clear routes.
1523+
await tester.pageBack();
1524+
await tester.pumpAndSettle();
1525+
pushedRoutes.clear();
1526+
1527+
connection.prepare(json: eg.newestGetMessagesResult(
1528+
foundOldest: true, messages: [message]).toJson());
1529+
// Tap just above the bottom of recipient header, below and outside of
1530+
// its channel name component.
1531+
await tester.tapAt(Offset(
1532+
channelNameRect.center.dx, recipientHeaderRect.bottom - 1));
1533+
await tester.pump();
1534+
check(pushedRoutes).single.isA<WidgetRoute>().page.isA<MessageListPage>()
1535+
.initNarrow.equals(ChannelNarrow(channel.streamId));
1536+
await tester.pumpAndSettle();
1537+
});
1538+
1539+
// Regression test for: https://github.com/zulip/zulip-flutter/issues/1179
1540+
testWidgets("navigates to TopicNarrow when tapping above or below topic name in recipient header", (tester) async {
1541+
await prepare(tester);
1542+
1543+
final topicNameFinder = find.descendant(
1544+
of: recipientHeaderFinder,
1545+
matching: find.text(testTopic));
1546+
final topicNameRect = tester.getRect(topicNameFinder);
1547+
1548+
connection.prepare(json: eg.newestGetMessagesResult(
1549+
foundOldest: true, messages: [message]).toJson());
1550+
// Tap just right below the top of recipient header, above and outside of
1551+
// its topic name component.
1552+
await tester.tapAt(Offset(
1553+
topicNameRect.center.dx, recipientHeaderRect.top + 1));
1554+
await tester.pump();
1555+
check(pushedRoutes).single.isA<WidgetRoute>().page.isA<MessageListPage>()
1556+
.initNarrow.equals(TopicNarrow(channel.streamId, message.topic));
1557+
await tester.pumpAndSettle();
1558+
1559+
// Navigate back to original page and clear routes.
1560+
await tester.pageBack();
1561+
await tester.pumpAndSettle();
1562+
pushedRoutes.clear();
1563+
1564+
connection.prepare(json: eg.newestGetMessagesResult(
1565+
foundOldest: true, messages: [message]).toJson());
1566+
// Tap just above the bottom of recipient header, below and outside of
1567+
// its topic name component.
1568+
await tester.tapAt(Offset(
1569+
topicNameRect.center.dx, recipientHeaderRect.bottom - 1));
1570+
await tester.pump();
1571+
check(pushedRoutes).single.isA<WidgetRoute>().page.isA<MessageListPage>()
1572+
.initNarrow.equals(TopicNarrow(channel.streamId, message.topic));
1573+
await tester.pumpAndSettle();
1574+
});
1575+
});
14731576
}

0 commit comments

Comments
 (0)