Skip to content

Commit 86e4bb7

Browse files
authored
SES-4388 : Auto scrolling issues (#1547)
1 parent b8c8b21 commit 86e4bb7

File tree

4 files changed

+26
-23
lines changed

4 files changed

+26
-23
lines changed

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -627,11 +627,10 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
627627

628628
private fun setupWindowInsets() {
629629
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, windowInsets ->
630-
val systemBarsInsets =
631-
windowInsets.getInsets(WindowInsetsCompat.Type.navigationBars() or WindowInsetsCompat.Type.ime())
630+
val navInsets = windowInsets.getInsets(WindowInsetsCompat.Type.navigationBars())
631+
val imeInsets = windowInsets.getInsets(WindowInsetsCompat.Type.ime())
632632

633-
val imeHeight = windowInsets.getInsets(WindowInsetsCompat.Type.ime()).bottom
634-
val keyboardVisible = imeHeight > 0
633+
val keyboardVisible = imeInsets.bottom > 0
635634

636635
if (keyboardVisible != isKeyboardVisible) {
637636
isKeyboardVisible = keyboardVisible
@@ -645,10 +644,10 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
645644
}
646645

647646
binding.bottomSpacer.updateLayoutParams<LayoutParams> {
648-
height = systemBarsInsets.bottom
647+
height = if (keyboardVisible) imeInsets.bottom else navInsets.bottom
649648
}
650649

651-
windowInsets.inset(systemBarsInsets)
650+
windowInsets
652651
}
653652
}
654653

@@ -795,7 +794,8 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
795794
} else {
796795
// If there are new data updated, we'll try to stay scrolled at the bottom (if we were at the bottom).
797796
// scrolled to bottom has a leniency of 50dp, so if we are within the 50dp but not fully at the bottom, scroll down
798-
if (binding.conversationRecyclerView.isNearBottom && !binding.conversationRecyclerView.isFullyScrolled) {
797+
if (binding.conversationRecyclerView.isNearBottom &&
798+
!binding.conversationRecyclerView.isFullyScrolled) {
799799
binding.conversationRecyclerView.handleScrollToBottom()
800800
}
801801
}
@@ -817,7 +817,6 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
817817

818818
// called from onCreate
819819
private fun setUpRecyclerView() {
820-
binding.conversationRecyclerView.applyImeBottomPadding()
821820
binding.conversationRecyclerView.adapter = adapter
822821
val layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
823822
binding.conversationRecyclerView.layoutManager = layoutManager
@@ -1998,6 +1997,9 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
19981997
if (sentMessageInfo != null) {
19991998
messageToScrollAuthor.set(sentMessageInfo.first)
20001999
messageToScrollTimestamp.set(sentMessageInfo.second)
2000+
binding.conversationRecyclerView.postDelayed({
2001+
binding.conversationRecyclerView.handleScrollToBottom()
2002+
}, 500L)
20012003
}
20022004
}
20032005

@@ -2115,7 +2117,7 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
21152117
if (isShowingAttachmentOptions) { toggleAttachmentOptions() }
21162118

21172119
// Keep it fixed on the bottom right away
2118-
binding.conversationRecyclerView.handleScrollToBottom()
2120+
binding.conversationRecyclerView.handleScrollToBottom(true)
21192121

21202122
// do the heavy work in the bg
21212123
lifecycleScope.launch(Dispatchers.Default) {
@@ -2680,7 +2682,6 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
26802682
searchViewModel.onSearchOpened()
26812683
binding.searchBottomBar.visibility = View.VISIBLE
26822684
binding.searchBottomBar.setData(0, 0, searchViewModel.searchQuery.value)
2683-
binding.inputBar.visibility = View.GONE
26842685
binding.root.requestApplyInsets()
26852686

26862687
}
@@ -2689,7 +2690,6 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
26892690
viewModel.onSearchClosed()
26902691
searchViewModel.onSearchClosed()
26912692
binding.searchBottomBar.visibility = View.GONE
2692-
binding.inputBar.visibility = View.VISIBLE
26932693
binding.root.requestApplyInsets()
26942694
adapter.onSearchQueryUpdated(null)
26952695
invalidateOptionsMenu()
@@ -2720,9 +2720,7 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
27202720
binding.conversationRecyclerView.scrollToPosition(position)
27212721

27222722
if (highlight) {
2723-
runOnUiThread {
2724-
highlightViewAtPosition(position)
2725-
}
2723+
runOnUiThread { highlightViewAtPosition(position) }
27262724
}
27272725
} else {
27282726
onMessageNotFound?.run()

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,11 @@ class ConversationViewModel @AssistedInject constructor(
334334

335335
init {
336336
viewModelScope.launch {
337-
combine(
338-
recipientFlow,
337+
combine(recipientFlow,
339338
legacyGroupDeprecationManager.deprecationState,
340-
::getInputBarState
341-
).collectLatest {
339+
_searchOpened) { r, dep, searchOpen ->
340+
getInputBarState(r, dep, searchOpen)
341+
}.collectLatest {
342342
_inputBarState.value = it
343343
}
344344
}
@@ -430,12 +430,13 @@ class ConversationViewModel @AssistedInject constructor(
430430

431431
private fun getInputBarState(
432432
recipient: Recipient,
433-
deprecationState: LegacyGroupDeprecationManager.DeprecationState
433+
deprecationState: LegacyGroupDeprecationManager.DeprecationState,
434+
searchOpen: Boolean
434435
): InputBarState {
435436
val currentCharLimitState = _inputBarState.value.charLimitState
436437
return when {
437438
// prioritise cases that demand the input to be hidden
438-
!shouldShowInput(recipient, deprecationState) -> InputBarState(
439+
searchOpen || !shouldShowInput(recipient, deprecationState) -> InputBarState(
439440
contentState = InputBarContentState.Hidden,
440441
enableAttachMediaControls = false,
441442
charLimitState = currentCharLimitState

app/src/main/java/org/thoughtcrime/securesms/ui/components/ConversationAppBar.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.height
1717
import androidx.compose.foundation.layout.heightIn
1818
import androidx.compose.foundation.layout.padding
1919
import androidx.compose.foundation.layout.size
20+
import androidx.compose.foundation.layout.statusBarsPadding
2021
import androidx.compose.foundation.layout.systemBars
2122
import androidx.compose.foundation.layout.width
2223
import androidx.compose.foundation.layout.windowInsetsTopHeight
@@ -163,7 +164,7 @@ fun ConversationAppBar(
163164
true -> {
164165
Row(
165166
modifier = Modifier
166-
.windowInsetsTopHeight(WindowInsets.systemBars)
167+
.statusBarsPadding()
167168
.padding(horizontal = LocalDimensions.current.smallSpacing)
168169
.heightIn(min = LocalDimensions.current.appBarHeight),
169170
verticalAlignment = Alignment.CenterVertically,

app/src/main/java/org/thoughtcrime/securesms/util/adapter/RecyclerViewUtils.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ fun RecyclerView.applyImeBottomPadding() {
2020
}
2121

2222
// Handle scroll logic
23-
fun RecyclerView.handleScrollToBottom() {
23+
fun RecyclerView.handleScrollToBottom(fastScroll: Boolean = false) {
2424
val layoutManager = this.layoutManager as LinearLayoutManager
2525
val last = this.adapter?.itemCount?.minus(1)?.coerceAtLeast(0) ?: return
2626

27+
if (last < 0) return
28+
2729
val bottomOffset = this.paddingBottom
2830

29-
if (layoutManager.isSmoothScrolling) {
31+
if (layoutManager.isSmoothScrolling || fastScroll) {
3032
// second tap = instant align
3133
layoutManager.scrollToPositionWithOffset(last, bottomOffset)
3234
return
@@ -41,6 +43,7 @@ fun RecyclerView.handleScrollToBottom() {
4143
return (boxEnd - viewEnd) - bottomOffset
4244
}
4345
}
46+
4447
scroller.targetPosition = last
4548
layoutManager.startSmoothScroll(scroller)
4649
}

0 commit comments

Comments
 (0)