Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit f46f968

Browse files
Sam1301timabbott
authored andcommitted
Maintain scroll position in case of Load position ABOVE messages.
Account for message headers generated when messages are loaded above a list of messages. This is important because message headers are also counted as items in the recyclerview and hence when retaining the position of visible message at the top of list, we need to account for all the message headers generated for the set of LoadPosition.ABOVE messages. Fixes #353.
1 parent c6c1e04 commit f46f968

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

app/src/main/java/com/zulip/android/activities/MessageListFragment.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,16 @@ public void onMessages(Message[] messages, LoadPosition pos,
435435

436436
if (pos == LoadPosition.ABOVE) {
437437
adapter.setHeaderShowing(moreAbove);
438+
/* if we don't account for message headers generated, a scroll jitter is observed
439+
whenever messages are loaded ABOVE as the original top message's position is not
440+
retained. We also need to account for the message header of original top message in
441+
order to retain the correct scroll position.
442+
*/
443+
438444
// Restore the position of the top item
439-
this.recyclerView.scrollToPosition(topPosBefore + addedCount);
445+
// account for generated message headers
446+
// +1 for the header of top item
447+
this.recyclerView.scrollToPosition(topPosBefore + addedCount + headerParents + 1);
440448

441449
if (noFurtherMessages) {
442450
loadedToTop = true;

0 commit comments

Comments
 (0)