From eadc990675b3bce89d603a4983eb6832a89b4081 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Thu, 23 Sep 2021 18:18:18 +0200 Subject: [PATCH] Scroll to bottom of chat after sending a message Change-Id: I54f71bfe5e5b9f0bbeeafa1b0faa3e9992da442c --- .../home/room/detail/RoomDetailFragment.kt | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt index 7075ee0752..608cc50c57 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt @@ -791,15 +791,8 @@ class RoomDetailFragment @Inject constructor( private fun setupJumpToBottomView() { views.jumpToBottomView.visibility = View.INVISIBLE views.jumpToBottomView.debouncedClicks { - roomDetailViewModel.handle(RoomDetailAction.ExitTrackingUnreadMessagesState) views.jumpToBottomView.visibility = View.INVISIBLE - if (!roomDetailViewModel.timeline.isLive) { - scrollOnNewMessageCallback.forceScrollOnNextUpdate() - roomDetailViewModel.timeline.restartWithEventId(null) - } else { - roomDetailViewModel.timeline.setInitialEventId(null) - layoutManager.scrollToPositionWithOffset(0, 0) - } + doJumpToBottom() } jumpToBottomViewVisibilityManager = JumpToBottomViewVisibilityManager( @@ -810,6 +803,17 @@ class RoomDetailFragment @Inject constructor( ) } + private fun doJumpToBottom() { + roomDetailViewModel.handle(RoomDetailAction.ExitTrackingUnreadMessagesState) + if (!roomDetailViewModel.timeline.isLive) { + scrollOnNewMessageCallback.forceScrollOnNextUpdate() + roomDetailViewModel.timeline.restartWithEventId(null) + } else { + roomDetailViewModel.timeline.setInitialEventId(null) + layoutManager.scrollToPositionWithOffset(0, 0) + } + } + private fun setupJumpToReadMarkerView() { views.jumpToReadMarkerView.setOnClickListener { onJumpToReadMarkerClicked() @@ -1349,6 +1353,8 @@ class RoomDetailFragment @Inject constructor( lockSendButton = true roomDetailViewModel.handle(RoomDetailAction.SendMessage(text, vectorPreferences.isMarkdownEnabled())) emojiPopup.dismiss() + + doJumpToBottom() } }