-
Notifications
You must be signed in to change notification settings - Fork 27
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
Conversation
…ghlighting added to match iOS
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) |
There was a problem hiding this comment.
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 temporaryScrollListener
s trying do highlight. Maybe that's a correct behavior?
There was a problem hiding this comment.
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
…gle scrollListener
…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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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.