mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-03-14 09:45:42 +00:00
ios: fix search (#5715)
This commit is contained in:
parent
a3a27b250c
commit
a0560a5ad0
1 changed files with 23 additions and 18 deletions
|
@ -494,7 +494,7 @@ struct ChatView: View {
|
|||
|
||||
Button ("Cancel") {
|
||||
closeSearch()
|
||||
Task { await loadChat(chat: chat) }
|
||||
searchTextChanged("")
|
||||
}
|
||||
}
|
||||
.padding(.horizontal)
|
||||
|
@ -585,23 +585,8 @@ struct ChatView: View {
|
|||
.padding(.vertical, -100)
|
||||
.onTapGesture { hideKeyboard() }
|
||||
.onChange(of: searchText) { s in
|
||||
guard showSearch else { return }
|
||||
Task {
|
||||
await loadChat(chat: chat, search: s)
|
||||
mergedItems.boxedValue = MergedItems.create(im.reversedChatItems, revealedItems, im.chatState)
|
||||
await MainActor.run {
|
||||
scrollView.updateItems(mergedItems.boxedValue.items)
|
||||
}
|
||||
if !s.isEmpty {
|
||||
scrollView.scrollToBottom()
|
||||
} else if let index = scrollView.listState.items.lastIndex(where: { $0.hasUnread() }) {
|
||||
// scroll to the top unread item
|
||||
scrollView.scrollToItem(index)
|
||||
loadLastItems($loadingMoreItems, loadingBottomItems: $loadingBottomItems, chat)
|
||||
} else {
|
||||
scrollView.scrollToBottom()
|
||||
loadLastItems($loadingMoreItems, loadingBottomItems: $loadingBottomItems, chat)
|
||||
}
|
||||
if showSearch {
|
||||
searchTextChanged(s)
|
||||
}
|
||||
}
|
||||
.onChange(of: im.itemAdded) { added in
|
||||
|
@ -652,6 +637,26 @@ struct ChatView: View {
|
|||
}
|
||||
}
|
||||
|
||||
private func searchTextChanged(_ s: String) {
|
||||
Task {
|
||||
await loadChat(chat: chat, search: s)
|
||||
mergedItems.boxedValue = MergedItems.create(im.reversedChatItems, revealedItems, im.chatState)
|
||||
await MainActor.run {
|
||||
scrollView.updateItems(mergedItems.boxedValue.items)
|
||||
}
|
||||
if !s.isEmpty {
|
||||
scrollView.scrollToBottom()
|
||||
} else if let index = scrollView.listState.items.lastIndex(where: { $0.hasUnread() }) {
|
||||
// scroll to the top unread item
|
||||
scrollView.scrollToItem(index)
|
||||
loadLastItems($loadingMoreItems, loadingBottomItems: $loadingBottomItems, chat)
|
||||
} else {
|
||||
scrollView.scrollToBottom()
|
||||
loadLastItems($loadingMoreItems, loadingBottomItems: $loadingBottomItems, chat)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class FloatingButtonModel: ObservableObject {
|
||||
@Published var unreadAbove: Int = 0
|
||||
@Published var unreadBelow: Int = 0
|
||||
|
|
Loading…
Add table
Reference in a new issue