Skip to content

Commit 4dd73df

Browse files
Fix message view scrolling issues (#1449)
1 parent 891940a commit 4dd73df

File tree

2 files changed

+9
-31
lines changed

2 files changed

+9
-31
lines changed

app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,6 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
403403
lifecycleCoroutineScope = lifecycleScope
404404
)
405405
adapter.visibleMessageViewDelegate = this
406-
407-
// Register an AdapterDataObserver to scroll us to the bottom of the RecyclerView for if
408-
// we're already near the the bottom and the data changes.
409-
adapter.registerAdapterDataObserver(ConversationAdapterDataObserver(binding.conversationRecyclerView, adapter))
410-
411406
adapter
412407
}
413408

@@ -817,6 +812,12 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
817812
}
818813
}
819814
}
815+
} else {
816+
// If there are new data updated, we'll try to stay scrolled at the bottom (if we were at the bottom).
817+
// scrolled to bottom has a leniency of 50dp, so if we are within the 50dp but not fully at the bottom, scroll down
818+
if (binding.conversationRecyclerView.isNearBottom && !binding.conversationRecyclerView.isFullyScrolled) {
819+
binding.conversationRecyclerView.smoothScrollToPosition(adapter.itemCount)
820+
}
820821
}
821822

822823
handleRecyclerViewScrolled()
@@ -2754,17 +2755,4 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
27542755
}
27552756
}
27562757
}
2757-
2758-
// AdapterDataObserver implementation to scroll us to the bottom of the ConversationRecyclerView
2759-
// when we're already near the bottom and we send or receive a message.
2760-
inner class ConversationAdapterDataObserver(val recyclerView: ConversationRecyclerView, val adapter: ConversationAdapter) : RecyclerView.AdapterDataObserver() {
2761-
override fun onChanged() {
2762-
super.onChanged()
2763-
// scrolled to bottom has a leniency of 50dp, so if we are within the 50dp but not fully at the bottom, scroll down
2764-
if (recyclerView.isNearBottom && !recyclerView.isFullyScrolled) {
2765-
recyclerView.smoothScrollToPosition(adapter.itemCount)
2766-
}
2767-
}
2768-
}
2769-
27702758
}

app/src/main/java/org/thoughtcrime/securesms/util/GeneralUtilities.kt

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.thoughtcrime.securesms.util
22

33
import android.content.res.Resources
4+
import androidx.recyclerview.widget.LinearLayoutManager
45
import androidx.recyclerview.widget.RecyclerView
56
import kotlin.math.roundToInt
67

@@ -32,17 +33,6 @@ val RecyclerView.isNearBottom: Boolean
3233

3334
val RecyclerView.isFullyScrolled: Boolean
3435
get() {
35-
return scrollAmount == 0
36+
return (layoutManager as LinearLayoutManager).findLastCompletelyVisibleItemPosition() ==
37+
adapter!!.itemCount - 1
3638
}
37-
38-
val RecyclerView.scrollAmount: Int
39-
get() {
40-
val scrollOffset = computeVerticalScrollOffset().coerceAtLeast(0)
41-
val scrollExtent = computeVerticalScrollExtent()
42-
val scrollRange = computeVerticalScrollRange()
43-
44-
45-
// We're at the bottom if the offset + extent equals the range
46-
return scrollOffset + scrollExtent - scrollRange
47-
}
48-

0 commit comments

Comments
 (0)