1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

DROID-3183 Chats | Enhancement | Smoother scrolling when opening chat on unread messages (#2417)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Evgenii Kozlov 2025-05-20 16:40:25 +02:00 committed by GitHub
parent 300709aaa2
commit 945c4865c7
Signed by: github
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 7 deletions

View file

@ -125,10 +125,13 @@ class ChatContainer @Inject constructor(
val aroundUnread = loadAroundMessageOrder(
chat = chat,
order = initialState.oldestMessageOrderId.orEmpty()
).also {
val target = it.find { it.order == initialState.oldestMessageOrderId }
).also { messages ->
val target = messages.find { it.order == initialState.oldestMessageOrderId }
if (target != null) {
intent = Intent.ScrollToMessage(target.id)
intent = Intent.ScrollToMessage(
id = target.id,
smooth = false
)
}
}
addAll(aroundUnread)
@ -179,7 +182,10 @@ class ChatContainer @Inject constructor(
}
ChatStreamState(
messages = messages,
intent = Intent.ScrollToMessage(transform.message),
intent = Intent.ScrollToMessage(
id = transform.message,
smooth = true
),
state = state.state
)
}
@ -207,7 +213,10 @@ class ChatContainer @Inject constructor(
val target = messages.find { it.order == oldestReadOrderId }
ChatStreamState(
messages = messages,
intent = if (target != null) Intent.ScrollToMessage(target.id) else Intent.ScrollToBottom,
intent = if (target != null)
Intent.ScrollToMessage(target.id, smooth = true)
else
Intent.ScrollToBottom,
state = state.state
)
} else {
@ -626,7 +635,15 @@ class ChatContainer @Inject constructor(
)
sealed class Intent {
data class ScrollToMessage(val id: Id) : Intent()
/**
* Represents an intent to scroll to a specific message in the chat.
*
* @param id The unique identifier of the message to scroll to.
* @param smooth Determines whether the scrolling should be smooth (animated) or instantaneous.
* Defaults to `false` for performance reasons, as smooth scrolling may introduce
* delays or unnecessary animations in certain scenarios.
*/
data class ScrollToMessage(val id: Id, val smooth: Boolean = false) : Intent()
data class Highlight(val id: Id) : Intent()
data object ScrollToBottom : Intent()
data object None : Intent()

View file

@ -383,7 +383,11 @@ fun ChatScreen(
if (index >= 0) {
snapshotFlow { lazyListState.layoutInfo.totalItemsCount }
.first { it > index }
lazyListState.animateScrollToItem(index)
if (intent.smooth) {
lazyListState.animateScrollToItem(index)
} else {
lazyListState.scrollToItem(index)
}
awaitFrame()
} else {
Timber.d("DROID-2966 COMPOSE Could not find the scrolling target for the intent")