mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-25 12:04:22 +00:00
fix occasional race condition on long navigation
This commit is contained in:
+15
@@ -201,6 +201,21 @@ fun List<ChatSection>.chatItemPosition(chatItemId: Long): Int? {
|
||||
return null
|
||||
}
|
||||
|
||||
fun List<ChatSection>.revealedItemCount(): Int {
|
||||
var count = 0
|
||||
for (section in this) {
|
||||
for (item in section.items) {
|
||||
if (item.revealed) {
|
||||
count += item.items.size
|
||||
} else {
|
||||
count++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return count
|
||||
}
|
||||
|
||||
fun List<ChatSection>.dropTemporarySections() {
|
||||
val bottomSection = this.find { it.area == ChatSectionArea.Bottom }
|
||||
if (bottomSection != null) {
|
||||
|
||||
+2
-2
@@ -1009,7 +1009,7 @@ fun BoxWithConstraintsScope.ChatItemsList(
|
||||
val sections by remember { derivedStateOf { reversedChatItems.putIntoSections(revealedItems.value) } }
|
||||
val preloadItemsEnabled = remember { mutableStateOf(true) }
|
||||
val boundaries = remember { derivedStateOf { sections.map { it.boundary } } }
|
||||
val scrollPosition: (Int) -> Int = { idx -> min(listState.layoutInfo.totalItemsCount - 1, idx + 1 ) }
|
||||
val scrollPosition: (Int) -> Int = { idx -> min(sections.revealedItemCount() - 1, idx + 1 ) }
|
||||
|
||||
PreloadItems(chatInfo.id, listState, ChatPagination.UNTIL_PRELOAD_COUNT, preloadItemsEnabled, boundaries, loadMessages)
|
||||
val maxHeightRounded = with(LocalDensity.current) { maxHeight.roundToPx() }
|
||||
@@ -1067,9 +1067,9 @@ fun BoxWithConstraintsScope.ChatItemsList(
|
||||
}
|
||||
val chatSectionLoad = ChatSectionLoad(0, ChatSectionArea.Destination)
|
||||
apiLoadMessagesAroundItem(rhId = remoteHostId, chatModel = chatModel, chatInfo = chatInfo, aroundItemId = itemId, chatSectionLoad = chatSectionLoad)
|
||||
val idx = sections.chatItemPosition(itemId)
|
||||
|
||||
scope.launch {
|
||||
val idx = sections.chatItemPosition(itemId)
|
||||
if (idx != null) {
|
||||
listState.animateScrollToItem(scrollPosition(idx), -maxHeightRounded)
|
||||
withContext(Dispatchers.Main) {
|
||||
|
||||
Reference in New Issue
Block a user