jump to bottom

This commit is contained in:
Diogo
2024-11-06 11:15:51 +00:00
parent f8e69ea6e7
commit 5eaf563b96
2 changed files with 14 additions and 3 deletions
+1
View File
@@ -320,6 +320,7 @@ private func apiChatsResponse(_ r: ChatResponse) throws -> [ChatData] {
let loadItemsPerPage = 50
let preloadItem = 8
let idealChatListSize = 500
func apiGetChat(type: ChatType, id: Int64, search: String = "") async throws -> (Chat, Int?) {
let r = await chatSendCmd(.apiGetChat(type: type, id: id, pagination: .initial(count: loadItemsPerPage), search: search))
+13 -3
View File
@@ -75,7 +75,7 @@ struct ChatView: View {
VStack(spacing: 0) {
ZStack(alignment: .bottomTrailing) {
chatItemsList()
FloatingButtons(theme: theme, scrollModel: scrollModel, chat: chat)
FloatingButtons(theme: theme, scrollModel: scrollModel, chat: chat, onScrollToBottom: onScrollToBottom)
}
connectingText()
if selectedChatItems == nil {
@@ -476,6 +476,15 @@ struct ChatView: View {
}
}
private func onScrollToBottom() {
scrollModel.scrollToBottom()
if let g = im.gap {
let sliceSize = min(g.index, idealChatListSize)
im.gap = nil
im.reversedChatItems = Array(im.reversedChatItems[..<sliceSize])
}
}
private func getFirstUnreadItem() -> ChatItem? {
logger.error("[scrolling] \(im.reversedChatItems.count)")
@@ -571,6 +580,7 @@ struct ChatView: View {
let theme: AppTheme
let scrollModel: ReverseListScrollModel
let chat: Chat
let onScrollToBottom: () -> Void
@ObservedObject var model = FloatingButtonModel.shared
var body: some View {
@@ -611,14 +621,14 @@ struct ChatView: View {
.foregroundColor(theme.colors.primary)
}
.onTapGesture {
scrollModel.scrollToBottom()
onScrollToBottom()
}
} else if !model.isNearBottom {
circleButton {
Image(systemName: "chevron.down")
.foregroundColor(theme.colors.primary)
}
.onTapGesture { scrollModel.scrollToBottom() }
.onTapGesture { onScrollToBottom() }
}
}
.padding()