This commit is contained in:
Avently
2024-11-01 14:59:38 +07:00
parent d2a473c908
commit 20c4c02f63
3 changed files with 6 additions and 2 deletions
@@ -2309,6 +2309,10 @@ fun <T> MutableState<SnapshotStateList<T>>.removeAt(index: Int): T {
return res
}
fun <T> MutableState<SnapshotStateList<T>>.removeRange(fromIndex: Int, toIndex: Int) {
value = SnapshotStateList<T>().apply { addAll(value); removeRange(fromIndex, toIndex) }
}
fun <T> MutableState<SnapshotStateList<T>>.removeLast() {
value = SnapshotStateList<T>().apply { addAll(value); removeLast() }
}
@@ -218,7 +218,7 @@ fun List<ChatSection>.dropTemporarySections() {
if (bottomSection != null) {
val items = chatModel.chatItems.value
val itemsOutsideOfSection = items.size - 1 - bottomSection.boundary.maxIndex
chatModel.chatItems.value.removeRange(fromIndex = 0, toIndex = itemsOutsideOfSection + bottomSection.excessItemCount())
chatModel.chatItems.removeRange(fromIndex = 0, toIndex = itemsOutsideOfSection + bottomSection.excessItemCount())
chatModel.chatItemsSectionArea = mutableMapOf<Long, ChatSectionArea>().also { it.putAll(items.associate { it.id to ChatSectionArea.Bottom }) }
}
}
@@ -1072,7 +1072,7 @@ fun BoxScope.ChatItemsList(
itemsToDrop.forEach {
chatModel.chatItemsSectionArea.remove(it.id)
}
chatModel.chatItems.value.removeIf { chatModel.chatItemsSectionArea[it.id] == null }
chatModel.chatItems.removeAll { chatModel.chatItemsSectionArea[it.id] == null }
val newIdx = reversedChatItems.value.indexOfFirst { it.id == itemId }
listState.scrollToItem(scrollPosition.value(newIdx), -maxHeight.value)
}