From dc6bab7ae661528d27341973ee0d26d58c97e465 Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Thu, 9 Feb 2023 02:10:56 +0300 Subject: [PATCH] android: fixed broken autoscroll when a new message is coming (#1917) * android: fixed broken autoscroll when a new message is coming * spelling --- .../java/chat/simplex/app/views/chat/ChatView.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/chat/ChatView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/chat/ChatView.kt index b155f33f26..c9cb6d6f4f 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/chat/ChatView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/chat/ChatView.kt @@ -674,10 +674,18 @@ private fun ScrollToBottom(chatId: ChatId, listState: LazyListState, chatItems: .distinctUntilChanged() .filter { listState.layoutInfo.visibleItemsInfo.firstOrNull()?.key != it } .collect { - if (listState.firstVisibleItemIndex == 0) { - listState.animateScrollToItem(0) - } else { - listState.animateScrollBy(scrollDistance) + try { + if (listState.firstVisibleItemIndex == 0) { + listState.animateScrollToItem(0) + } else { + listState.animateScrollBy(scrollDistance) + } + } catch (e: CancellationException) { + /** + * When you tap and hold a finger on a lazy column with chatItems, and then you receive a message, + * this coroutine will be canceled with the message "Current mutation had a higher priority" because of animatedScroll. + * Which breaks auto-scrolling to bottom. So just ignoring the exception + * */ } } }