Прокрутка чата
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -190,6 +190,24 @@ fun ChatDetailScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 4. Авто-скролл к новым сообщениям
|
||||||
|
val firstMessageId = state.messages.firstOrNull()?.id
|
||||||
|
LaunchedEffect(firstMessageId) {
|
||||||
|
if (firstMessageId != null) {
|
||||||
|
// Если мы уже внизу (индекс 0) или это наше сообщение - скроллим вниз
|
||||||
|
val isAtBottom = listState.firstVisibleItemIndex <= 1
|
||||||
|
val isMyMessage = state.messages.firstOrNull()?.senderId == viewModel.getCurrentUserId()
|
||||||
|
|
||||||
|
if (isAtBottom || isMyMessage) {
|
||||||
|
listState.animateScrollToItem(0)
|
||||||
|
// Если мы внизу - помечаем сразу как прочитанное
|
||||||
|
if (isAtBottom && !isMyMessage) {
|
||||||
|
viewModel.markAsRead()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Автоматическая прокрутка и прочтение при инициализации и новых сообщениях
|
// Автоматическая прокрутка и прочтение при инициализации и новых сообщениях
|
||||||
LaunchedEffect(listItems.size) {
|
LaunchedEffect(listItems.size) {
|
||||||
if (listItems.isNotEmpty()) {
|
if (listItems.isNotEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user