Skip to content

SES-2145 - Fix re-scroll to bottom after clicking on original message in a reply #961

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

Merged
merged 9 commits into from
Feb 20, 2025

Conversation

AL-Session
Copy link
Contributor

Ticket:
SES-2145

Adjustments:
1.) Prevent re-scroll to bottom of conversation after clicking on the message snippet of the original message in a reply. We now smooth scroll to the original message to match iOS behaviour rather than performing an instant scroll which left the recycler view immediately in SCROLL_STATE_IDLE and allowed the scroll-to-last-message functionality to be triggered.

2.) Added highlight on successful scroll to original "replied-to" message to match iOS behaviour.

3.) Converted a few methods into expression-bodied equivalents as I came across them as there's no reason not to save some vertical real-estate when we can.

Potential test steps:
1.) Reply to a message which is on-screen then click the original message snippet in your reply - original message is highlighted without scrolling.

2.) Reply to a message which is off-screen then click the original message snippet in your reply - we scroll to the original message and highlight it when we get there.

Comment on lines 1796 to 1808
val temporaryScrollListener = object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
recyclerView.removeOnScrollListener(this)
recyclerView.findViewHolderForLayoutPosition(targetMessagePosition)?.let { viewHolder ->
(viewHolder.itemView as? VisibleMessageView)?.playHighlight()
?: Log.w(TAG, "View at position $targetMessagePosition is not a VisibleMessageView - cannot highlight.")
} ?: Log.w(TAG, "ViewHolder at position $targetMessagePosition is null - cannot highlight.")
}
}
}

binding.conversationRecyclerView.addOnScrollListener(temporaryScrollListener)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to have something calls scrollToMessageIfPossible again with a different timestamp before the the scroll settles? In which case there will be two temporaryScrollListeners trying do highlight. Maybe that's a correct behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While very unlikely, and clicking just after a click-to-scroll simply stops the scrolling, I've refactored to remove the temporary scrollListener and incorporated the functionality into the one-true scrollListener =D

Making sure the glow isn't clipped
Scrolling past the quoted view so that it isn't right at the top
…f github.com:session-foundation/session-android into fix/SES-2145-quoted-message-scroll-behaviour

Signed-off-by: alansley <[email protected]>
private val isScrolledToBottom: Boolean
get() = binding.conversationRecyclerView.isScrolledToBottom

private val isScrolledToWithin30dpOfBottom: Boolean
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was moved here but looks like it's unused

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

// Note: If the targeted message isn't the very first one then we scroll slightly past it to give it some breathing room.
// Also: The offset must be negative to provide room above it.
pendingHighlightMessagePosition = targetMessagePosition
targetedScrollOffsetPx = if (targetMessagePosition > 0) resources.getDimensionPixelSize(R.dimen.massive_spacing) * -1 else 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resources.getDimensionPixelSize(R.dimen.massive_spacing) * -1 can be lazily loaded into a property to avoid recalculating it each time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@AL-Session AL-Session merged commit 3ff39dc into dev Feb 20, 2025
1 check was pending
@AL-Session AL-Session deleted the fix/SES-2145-quoted-message-scroll-behaviour branch February 20, 2025 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants