diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index 9ff233be36..9a2f871fe5 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -474,7 +474,9 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate, } private val isScrolledToBottom: Boolean - get() = binding.conversationRecyclerView.isNearBottom + get() = with(binding.conversationRecyclerView){ + !canScrollVertically(1) || isNearBottom + } // When the user clicks on the original message in a reply then we scroll to and highlight that original // message. To do this we keep track of the replied-to message's location in the recycler view. @@ -2120,9 +2122,6 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate, if (sentMessageInfo != null) { messageToScrollAuthor.set(sentMessageInfo.first) messageToScrollTimestamp.set(sentMessageInfo.second) - binding.conversationRecyclerView.postDelayed({ - binding.conversationRecyclerView.handleScrollToBottom() - }, 500L) } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/GeneralUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/util/GeneralUtilities.kt index a19f89dae3..ab74ef8d89 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/GeneralUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/GeneralUtilities.kt @@ -1,6 +1,7 @@ package org.thoughtcrime.securesms.util import android.content.res.Resources +import android.util.Log import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import kotlin.math.roundToInt @@ -23,13 +24,23 @@ fun toDp(px: Float, resources: Resources): Float { return (px / scale) } -/** - * Returns true if the recyclerview is scrolled within 50dp of the bottom - */ val RecyclerView.isNearBottom: Boolean - get() = computeVerticalScrollOffset().coerceAtLeast(0) + - computeVerticalScrollExtent() + - toPx(50, resources) >= computeVerticalScrollRange() + get() { + val offset = computeVerticalScrollOffset().coerceAtLeast(0) + val extent = computeVerticalScrollExtent() + val range = computeVerticalScrollRange() + val thresholdPx = toPx(50, resources) + + // If there's no scrollable area, don't treat it as "near bottom" + if (range <= extent) { + return false + } + + val remaining = range - (offset + extent) // distance from bottom in px + + // true only when remaining distance to bottom <= 50dp + return remaining <= thresholdPx + } val RecyclerView.isFullyScrolled: Boolean get() {