Skip to content

Commit 092dc2d

Browse files
committed
msglist: Leave blank space for "mark as read" button so using it doesn't cause messages to shift
This commit addresses the issue of the message list shifting downwards when the "mark as read" button is pressed. The previous implementation would return an empty widget when the button was pressed and cause the message list to shift down. Now it takes a widget with a definite height, which is equal to the size of the button and won't cause the message list to shift down. Fixes: #562
1 parent 46b4577 commit 092dc2d

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

lib/widgets/message_list.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ class MarkAsReadWidget extends StatelessWidget {
464464
return AnimatedCrossFade(
465465
duration: const Duration(milliseconds: 300),
466466
crossFadeState: (unreadCount > 0) ? CrossFadeState.showSecond : CrossFadeState.showFirst,
467-
firstChild: const SizedBox.shrink(),
467+
// The height of the firstChild is the vertical padding of the secondChild in both directions + the minimumSize height of the secondChild
468+
firstChild: const SizedBox(height: 58),
468469
secondChild: SizedBox(width: double.infinity,
469470
// Design referenced from:
470471
// https://www.figma.com/file/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?type=design&node-id=132-9684&mode=design&t=jJwHzloKJ0TMOG4M-0

test/widgets/message_list_test.dart

+5-7
Original file line numberDiff line numberDiff line change
@@ -610,13 +610,11 @@ void main() {
610610

611611
group('MarkAsReadWidget', () {
612612
bool isMarkAsReadButtonVisible(WidgetTester tester) {
613-
// Zero height elements on the edge of a scrolling viewport
614-
// are treated as invisible for hit-testing, see
615-
// [SliverMultiBoxAdaptorElement.debugVisitOnstageChildren].
616-
// Set `skipOffstage: false` here to safely target the
617-
// [MarkAsReadWidget] even when it is inactive.
618-
return tester.getSize(
619-
find.byType(MarkAsReadWidget, skipOffstage: false)).height > 0;
613+
// The [MarkAsReadWidget] widget is an [AnimatedCrossFade] widget where
614+
// the [CrossFadeState.showSecond] state is when the "mark as read" button is visible
615+
// and the [CrossFadeState.showFirst] state is when the "mark as read" button is not visible.
616+
var animatedCrossFade = tester.widget<AnimatedCrossFade>(find.byType(AnimatedCrossFade));
617+
return animatedCrossFade.crossFadeState == CrossFadeState.showSecond;
620618
}
621619

622620
testWidgets('from read to unread', (WidgetTester tester) async {

0 commit comments

Comments
 (0)