fix: comment navigation at list ends (#982)

This commit is contained in:
Diego Beraldin 2024-06-15 09:11:49 +02:00 committed by GitHub
parent dd2f6432a5
commit fe55a626b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -959,7 +959,7 @@ class PostDetailViewModel(
} }
val viewIndex = val viewIndex =
if (newIndex == lastCommentNavigateIndex) { if (newIndex == lastCommentNavigateIndex) {
((lastCommentNavigateIndex ?: newIndex) - 1).coerceAtLeast(0) ((lastCommentNavigateIndex ?: newIndex) - 1).coerceAtLeast(1)
} else { } else {
newIndex newIndex
} }
@ -992,7 +992,7 @@ class PostDetailViewModel(
if (newIndex == lastCommentNavigateIndex) { if (newIndex == lastCommentNavigateIndex) {
(lastCommentNavigateIndex ?: newIndex) + 1 (lastCommentNavigateIndex ?: newIndex) + 1
} else { } else {
newIndex newIndex.coerceAtLeast(lastCommentNavigateIndex ?: 0)
} }
// save last scrolled index to make function strictly increasing // save last scrolled index to make function strictly increasing
lastCommentNavigateIndex = viewIndex lastCommentNavigateIndex = viewIndex