Adds option to enable/disable infinite scroll - #2172
Conversation
…end with enableInfiniteScroll disabled.
Currently translated at 100.0% (510 of 510 strings) Translation: Lemmy/jerboa Translate-URL: http://weblate.join-lemmy.org/projects/lemmy/jerboa/bg/
Currently translated at 43.1% (220 of 510 strings) Translation: Lemmy/jerboa Translate-URL: http://weblate.join-lemmy.org/projects/lemmy/jerboa/de/
Currently translated at 43.5% (222 of 510 strings) Translation: Lemmy/jerboa Translate-URL: http://weblate.join-lemmy.org/projects/lemmy/jerboa/de/
* Implement view pooling for AndroidViews * Fix lint --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
…emmyNet#2162) * Fix scroll stuck/glitchy in comments when scrolling up to an image * Remove postId from CommentBody cacheKey --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
…hen first starting the app.
… content instead of the selected community.
…ing to the top of the screen after loading posts.
…n enable/disable infinite scrolling.
| var nextPageCursor: PaginationCursor? = null | ||
| var page by mutableLongStateOf(1) | ||
|
|
||
| fun appendPage(nextPage: PaginationCursor?) { |
There was a problem hiding this comment.
This seems to be a dupe of nextPage but without pushing to the stack. Why is that necessary?
| val previousPageCursors = Stack<PaginationCursor?>() | ||
| var currentPageCursor: PaginationCursor? = null | ||
| var nextPageCursor: PaginationCursor? = null | ||
| var page by mutableLongStateOf(1) |
There was a problem hiding this comment.
Why did this need to change. I thought mutableStateOf only matter for functional components.
|
|
||
| class PaginationController { | ||
|
|
||
| val previousPageCursors = Stack<PaginationCursor?>() |
There was a problem hiding this comment.
In 1.0, we won't need this stack, as the PagedResponse returns a prev_page and next_page, so please add a TODO comment about that.
| onNext: () -> Unit, | ||
| onPrevious: () -> Unit, | ||
| onNextEnabled: Boolean = true |
There was a problem hiding this comment.
Define this sealed class to help with page types:
sealed class PageType {
data class Number(val data: Long) : PageType
data class Cursor(val data: PaginationCursor) : PageType
}In anticipation of 1.0, provide it with 3 things.
current: PageType?,
nextPage: PageType?,
prevPage: PageType?,Then do
onNext: (PageType) -> Unit,
onPrev: (PageType) -> Unit,You can remove onNextEnabled because you'll know this from giving it the nextPage
| onNextPage = { | ||
| personProfileViewModel.navigatePagination(profileId, 1) | ||
| }, | ||
| onPreviousPage = { |
There was a problem hiding this comment.
You'll now be able to use the correct cursor from the on page button click
| @Composable | ||
| fun PostListings( | ||
| posts: List<PostView>, | ||
| posts: List<PostView>?, |
There was a problem hiding this comment.
Just show the message for an empty list, which is what's returned by the api anyway. No need for an option.
There was a problem hiding this comment.
I did this to avoid showing "No more posts available" while loading the posts, I thought this could be seen as a bug by some users. This implementation allowed me to show the "No more posts available" only when the response returns an empty list of posts.
There was a problem hiding this comment.
while loading the posts
The screen above this shouldn't load this component until its ApiState == success, so loading should already be handled. IE the screen should have a ApiState == Loading indicator, that prevents even rendering the PostListings component otherwise.
There was a problem hiding this comment.
I don't know if I understood it correctly, but the HomeActivity loads the composable like this on the main branch:
val posts: List<PostView> = when (val postsRes = homeViewModel.postsRes) {
is ApiState.Failure -> {
apiErrorToast(ctx, postsRes.msg)
listOf()
}
is ApiState.Holder -> {
postsRes.data
}
else -> {
listOf()
}
}The else branch is triggered when postRes is ApiState.Loading, so the message "No more posts available" is displayed while loading because the list is empty. Changing the argument type to List<PostView>? was the easiest way I found to avoid displaying the message while loading the posts.
The CommunityScreen does it differently, though. It only loads the PostListings composable when postRes is ApiState.Holder. I can apply this logic on the HomeActivity, you want it to be like that?
CommunityScreen example:
when (val postsRes = communityViewModel.postsRes) {
ApiState.Empty -> {
ApiEmptyText()
}
is ApiState.Failure -> {
ApiErrorText(postsRes.msg)
}
is ApiState.Holder -> { /* load composable */ }|
Hi, thanks for the comments. I'm currently looking into moving the logic from |
|
No problem. Its going to take me a long time to get the |
…le and also saves it in the API.
…o-fm/jerboa into feature/toggle-pagination
| swipeToActionPreset = swipeToActionPreset, | ||
| ) | ||
| item { | ||
| if (enableInfiniteScroll) Spacer(modifier = Modifier.height(100.dp)) |
There was a problem hiding this comment.
This size needs to be defined somewhere, and it should be part of the paginator row margins.
| } | ||
| item { | ||
| if (!enableInfiniteScroll) { | ||
| PaginationButton( |
There was a problem hiding this comment.
Pretty sure I have a comment in the last review about renaming this.
Here are a few pictures of the navigation without infinite scroll
And here's a video :)
scroll.mp4