Skip to content

Commit 5499616

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 5499616

File tree

2 files changed

+105
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)