Skip to content

msglist: Leave blank space for "mark as read" button so using it doesn't cause messages to shift #565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 33 additions & 28 deletions lib/widgets/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -461,34 +461,39 @@ class MarkAsReadWidget extends StatelessWidget {
final zulipLocalizations = ZulipLocalizations.of(context);
final store = PerAccountStoreWidget.of(context);
final unreadCount = store.unreads.countInNarrow(narrow);
return AnimatedCrossFade(
duration: const Duration(milliseconds: 300),
crossFadeState: (unreadCount > 0) ? CrossFadeState.showSecond : CrossFadeState.showFirst,
firstChild: const SizedBox.shrink(),
secondChild: SizedBox(width: double.infinity,
// Design referenced from:
// https://www.figma.com/file/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?type=design&node-id=132-9684&mode=design&t=jJwHzloKJ0TMOG4M-0
child: Padding(
// vertical padding adjusted for tap target height (48px) of button
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10 - ((48 - 38) / 2)),
child: FilledButton.icon(
style: FilledButton.styleFrom(
backgroundColor: _UnreadMarker.color,
minimumSize: const Size.fromHeight(38),
textStyle:
// Restate [FilledButton]'s default, which inherits from
// [zulipTypography]…
Theme.of(context).textTheme.labelLarge!
// …then clobber some attributes to follow Figma:
.merge(const TextStyle(
fontSize: 18,
height: (23 / 18))
.merge(weightVariableTextStyle(context, wght: 400))),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(7)),
),
onPressed: () => _handlePress(context),
icon: const Icon(Icons.playlist_add_check),
label: Text(zulipLocalizations.markAllAsReadLabel)))));
final areMessagesRead = unreadCount == 0;

return IgnorePointer(
ignoring: areMessagesRead,
child: AnimatedOpacity(
opacity: areMessagesRead ? 0 : 1,
duration: Duration(milliseconds: areMessagesRead ? 2000 : 300),
curve: Curves.easeOut,
child: SizedBox(width: double.infinity,
// Design referenced from:
// https://www.figma.com/file/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?type=design&node-id=132-9684&mode=design&t=jJwHzloKJ0TMOG4M-0
child: Padding(
// vertical padding adjusted for tap target height (48px) of button
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10 - ((48 - 38) / 2)),
child: FilledButton.icon(
style: FilledButton.styleFrom(
backgroundColor: _UnreadMarker.color,
minimumSize: const Size.fromHeight(38),
textStyle:
// Restate [FilledButton]'s default, which inherits from
// [zulipTypography]…
Theme.of(context).textTheme.labelLarge!
// …then clobber some attributes to follow Figma:
.merge(const TextStyle(
fontSize: 18,
height: (23 / 18))
.merge(weightVariableTextStyle(context, wght: 400))),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(7)),
),
onPressed: () => _handlePress(context),
icon: const Icon(Icons.playlist_add_check),
label: Text(zulipLocalizations.markAllAsReadLabel))))),
);
}
}

Expand Down
36 changes: 29 additions & 7 deletions test/widgets/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -610,13 +610,10 @@ void main() {

group('MarkAsReadWidget', () {
bool isMarkAsReadButtonVisible(WidgetTester tester) {
// Zero height elements on the edge of a scrolling viewport
// are treated as invisible for hit-testing, see
// [SliverMultiBoxAdaptorElement.debugVisitOnstageChildren].
// Set `skipOffstage: false` here to safely target the
// [MarkAsReadWidget] even when it is inactive.
return tester.getSize(
find.byType(MarkAsReadWidget, skipOffstage: false)).height > 0;
final zulipLocalizations = GlobalLocalizations.zulipLocalizations;
final finder = find.text(
zulipLocalizations.markAllAsReadLabel).hitTestable();
return finder.evaluate().isNotEmpty;
}

testWidgets('from read to unread', (WidgetTester tester) async {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to updating the existing tests, this change should add a new test: we want to check that the messages don't shift position when marking as read.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a new test that addresses this. It checks if the vertical position of the first message item is the same before and after the "Mark all messages as read" button is pressed.

Expand Down Expand Up @@ -648,6 +645,31 @@ void main() {
check(isMarkAsReadButtonVisible(tester)).isFalse();
});

testWidgets("messages don't shift position", (WidgetTester tester) async {
final message = eg.streamMessage(flags: []);
final unreadMsgs = eg.unreadMsgs(streams:[
UnreadStreamSnapshot(topic: message.subject, streamId: message.streamId,
unreadMessageIds: [message.id])
]);
await setupMessageListPage(tester,
messages: [message], unreadMsgs: unreadMsgs);
check(isMarkAsReadButtonVisible(tester)).isTrue();
check(tester.widgetList(find.byType(MessageItem))).length.equals(1);
final before = tester.getTopLeft(find.byType(MessageItem)).dy;

store.handleEvent(UpdateMessageFlagsAddEvent(
id: 1,
flag: MessageFlag.read,
messages: [message.id],
all: false,
));
await tester.pumpAndSettle();
check(isMarkAsReadButtonVisible(tester)).isFalse();
check(tester.widgetList(find.byType(MessageItem))).length.equals(1);
final after = tester.getTopLeft(find.byType(MessageItem)).dy;
check(after).equals(before);
});

group('onPressed behavior', () {
final message = eg.streamMessage(flags: []);
final unreadMsgs = eg.unreadMsgs(streams: [
Expand Down
Loading