Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not remembering position in all cases #936

Closed
nikclayton opened this issue Sep 13, 2024 · 0 comments · Fixed by #941
Closed

Not remembering position in all cases #936

nikclayton opened this issue Sep 13, 2024 · 0 comments · Fixed by #941

Comments

@nikclayton
Copy link
Contributor

Occasional reports (through to 2.8.1) that the reading position is not remembered in all cases.

Current code looks something like this:

    fun saveVisibleId(statusId: String? = null) {
        val id = statusId ?: layoutManager.findFirstCompletelyVisibleItemPosition()
            .takeIf { it != RecyclerView.NO_POSITION }
            ?.let { adapter.snapshot().getOrNull(it)?.id }
        
        id?.let {
            Timber.d("saveVisibleId: Saving ID: %s", it)
            viewModel.accept(InfallibleUiAction.SaveVisibleId(visibleId = it))
        } ?: Timber.d("saveVisibleId: Not saving, as no ID was visible")
    }

The problem is -- what happens if there is no item that is completely visible.

Consider a post that is longer than the screen. It's not completely visible, so id is null and the position is not saved.

Or consider two posts that are individually shorter than the screen, but if the user is scrolled so that they are both visible, neither of them is fully visible. Again, since neither post is fully visible id will be null and the position is not saved.

Solution is probably to fall back to the saving the position of the last visible item if no item is fully visible.

nikclayton added a commit that referenced this issue Sep 25, 2024
Previous code saved the reading position of a fully visible status. But
there are situations where no status is fully visible.

1. The user is in the middle of viewing a status longer than the screen
height, and the top/bottom of the status are off the top/bottom of the
screen.

2. The user has scrolled between two statuses. Collectively they are
longer than the screen height, and the top of one status is off the
top of the screen and the bottom of the other status is off the bottom
of the screen.

In both cases the user's reading position was not saved.

In these situations use the ID of the status closest to the bottom of
the screen, even if not fully visible. This should ensure the user
never missing anything.

Fixes #936
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant