mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
jump to bottom
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user