Skip to content

Commit 579bbdb

Browse files
committed
msglist: Update layout of MessageWithPossibleSender
Adjusted 'fetch older messages on scroll' test as new layout is more compact given consecutive messages with the same sender.
1 parent 7bd88af commit 579bbdb

File tree

2 files changed

+63
-54
lines changed

2 files changed

+63
-54
lines changed

lib/widgets/message_list.dart

Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,9 @@ String formatHeaderDate(
841841
}
842842

843843
/// A Zulip message, showing the sender's name and avatar if specified.
844+
// Design referenced from:
845+
// - https://github.com/zulip/zulip-mobile/issues/5511
846+
// - https://www.figma.com/file/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?type=design&node-id=144-12134&mode=design&t=Vkvdz5hmNVd5um1u-0
844847
class MessageWithPossibleSender extends StatelessWidget {
845848
const MessageWithPossibleSender({super.key, required this.item});
846849

@@ -852,61 +855,67 @@ class MessageWithPossibleSender extends StatelessWidget {
852855

853856
final senderRow = item.showSender
854857
? Padding(
855-
padding: const EdgeInsets.fromLTRB(3, 6, 11, 0),
856-
child: GestureDetector(
857-
onTap: () => Navigator.push(context,
858-
ProfilePage.buildRoute(context: context,
859-
userId: message.senderId)),
860-
child: Avatar(size: 35, borderRadius: 4,
861-
userId: message.senderId)))
862-
: const SizedBox(width: 3 + 35 + 11);
858+
padding: const EdgeInsets.only(top: 6, left: 16, right: 16),
859+
child: Row(
860+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
861+
crossAxisAlignment: CrossAxisAlignment.baseline,
862+
textBaseline: TextBaseline.alphabetic,
863+
children: [
864+
Flexible(
865+
child: GestureDetector(
866+
onTap: () => Navigator.push(context,
867+
ProfilePage.buildRoute(context: context,
868+
userId: message.senderId)),
869+
child: Row(
870+
children: [
871+
Avatar(size: 32, borderRadius: 3, userId: message.senderId),
872+
const SizedBox(width: 8),
873+
Flexible(
874+
child: Text(message.senderFullName, // TODO get from user data
875+
style: const TextStyle(
876+
fontFamily: 'Source Sans 3',
877+
fontSize: 18,
878+
height: (22 / 18),
879+
).merge(weightVariableTextStyle(context, wght: 600,
880+
wghtIfPlatformRequestsBold: 900)),
881+
overflow: TextOverflow.ellipsis)),
882+
]))),
883+
Text(
884+
_kMessageTimestampFormat.format(
885+
DateTime.fromMillisecondsSinceEpoch(1000 * message.timestamp)),
886+
style: TextStyle(
887+
color: _kMessageTimestampColor,
888+
fontFamily: 'Source Sans 3',
889+
fontSize: 16,
890+
height: (18 / 16),
891+
fontFeatures: const [FontFeature.enable('c2sc'), FontFeature.enable('smcp')],
892+
).merge(weightVariableTextStyle(context))),
893+
]),
894+
) : null;
863895

864896
return GestureDetector(
865897
behavior: HitTestBehavior.translucent,
866898
onLongPress: () => showMessageActionSheet(context: context, message: message),
867-
// TODO clean up this layout, by less precisely imitating web
868-
child: Padding(
869-
padding: const EdgeInsets.only(top: 2, bottom: 3, left: 8, right: 8),
870-
child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
871-
senderRow,
872-
Expanded(
873-
child: Column(
874-
crossAxisAlignment: CrossAxisAlignment.stretch,
875-
children: [
876-
if (item.showSender) ...[
877-
const SizedBox(height: 3),
878-
GestureDetector(
879-
onTap: () => Navigator.push(context,
880-
ProfilePage.buildRoute(context: context,
881-
userId: message.senderId)),
882-
child: Text(message.senderFullName, // TODO get from user data
883-
style: const TextStyle(
884-
fontFamily: 'Source Sans 3',
885-
fontSize: 18,
886-
height: (22 / 18),
887-
).merge(weightVariableTextStyle(context, wght: 600,
888-
wghtIfPlatformRequestsBold: 900)))),
889-
const SizedBox(height: 4),
890-
],
891-
MessageContent(message: message, content: item.content),
892-
if ((message.reactions?.total ?? 0) > 0)
893-
ReactionChipsList(messageId: message.id, reactions: message.reactions!)
894-
])),
895-
Container(
896-
width: 80,
897-
padding: const EdgeInsets.only(top: 4, right: 16 - 8),
898-
alignment: Alignment.topRight,
899-
child: Text(
900-
_kMessageTimestampFormat.format(
901-
DateTime.fromMillisecondsSinceEpoch(1000 * message.timestamp)),
902-
style: TextStyle(
903-
color: _kMessageTimestampColor,
904-
fontFamily: 'Source Sans 3',
905-
fontSize: 16,
906-
height: (18 / 16),
907-
fontFeatures: const [FontFeature.enable('c2sc'), FontFeature.enable('smcp')],
908-
).merge(weightVariableTextStyle(context)))),
909-
])));
899+
child: Column(
900+
children: [
901+
if (senderRow != null) senderRow,
902+
Row(
903+
crossAxisAlignment: CrossAxisAlignment.start,
904+
children: [
905+
const SizedBox(width: 16),
906+
Expanded(
907+
child: Padding(
908+
padding: const EdgeInsets.symmetric(vertical: 4),
909+
child: Column(
910+
crossAxisAlignment: CrossAxisAlignment.stretch,
911+
children: [
912+
MessageContent(message: message, content: item.content),
913+
if ((message.reactions?.total ?? 0) > 0)
914+
ReactionChipsList(messageId: message.id, reactions: message.reactions!)
915+
]))),
916+
const SizedBox(width: 16),
917+
]),
918+
]));
910919
}
911920
}
912921

test/widgets/message_list_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ void main() {
8686

8787
testWidgets('basic', (tester) async {
8888
await setupMessageListPage(tester, foundOldest: false,
89-
messages: List.generate(200, (i) => eg.streamMessage(id: 950 + i, sender: eg.selfUser)));
90-
check(itemCount(tester)).equals(203);
89+
messages: List.generate(300, (i) => eg.streamMessage(id: 950 + i, sender: eg.selfUser)));
90+
check(itemCount(tester)).equals(303);
9191

9292
// Fling-scroll upward...
9393
await tester.fling(find.byType(MessageListPage), const Offset(0, 300), 8000);
@@ -100,7 +100,7 @@ void main() {
100100
await tester.pump(Duration.zero); // Allow a frame for the response to arrive.
101101

102102
// Now we have more messages.
103-
check(itemCount(tester)).equals(303);
103+
check(itemCount(tester)).equals(403);
104104
});
105105

106106
testWidgets('observe double-fetch glitch', (tester) async {

0 commit comments

Comments
 (0)