Skip to content

Commit

Permalink
msglist: Add 36px space at bottom, to reinforce that end-of-feed is r…
Browse files Browse the repository at this point in the history
…eached

As requested by Vlad (same link as in a code comment):
  https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/flutter.3A.20Mark-as-read/near/1680603

Fixes: #400
  • Loading branch information
chrisbobbe authored and gnprice committed Nov 20, 2023
1 parent 8f67079 commit 56ab395
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions lib/widgets/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,10 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
final valueKey = key as ValueKey;
final index = model!.findItemWithMessageId(valueKey.value);
if (index == -1) return null;
return length - 1 - (index - 1);
return length - 1 - (index - 2);
},
controller: scrollController,
itemCount: length + 1,
itemCount: length + 2,
// Setting reverse: true means the scroll starts at the bottom.
// Flipping the indexes (in itemBuilder) means the start/bottom
// has the latest messages.
Expand All @@ -305,9 +305,13 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
// TODO on new message when scrolled up, anchor scroll to what's in view
reverse: true,
itemBuilder: (context, i) {
if (i == 0) return MarkAsReadWidget(narrow: widget.narrow);
// To reinforce that the end of the feed has been reached:
// https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/flutter.3A.20Mark-as-read/near/1680603
if (i == 0) return const SizedBox(height: 36);

final data = model!.items[length - 1 - (i - 1)];
if (i == 1) return MarkAsReadWidget(narrow: widget.narrow);

final data = model!.items[length - 1 - (i - 2)];
switch (data) {
case MessageListHistoryStartItem():
return const Center(
Expand Down
4 changes: 2 additions & 2 deletions test/widgets/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void main() {
testWidgets('basic', (tester) async {
await setupMessageListPage(tester, foundOldest: false,
messages: List.generate(200, (i) => eg.streamMessage(id: 950 + i, sender: eg.selfUser)));
check(itemCount(tester)).equals(202);
check(itemCount(tester)).equals(203);

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

// Now we have more messages.
check(itemCount(tester)).equals(302);
check(itemCount(tester)).equals(303);
});

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

0 comments on commit 56ab395

Please sign in to comment.