keyboard fix
This commit is contained in:
parent
359b516272
commit
9952ca6d2b
@ -6,6 +6,9 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
#if canImport(UIKit)
|
||||||
|
import UIKit
|
||||||
|
#endif
|
||||||
|
|
||||||
struct ChatsTab: View {
|
struct ChatsTab: View {
|
||||||
var currentUserId: String?
|
var currentUserId: String?
|
||||||
@ -125,7 +128,9 @@ struct ChatsTab: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.listStyle(.plain)
|
.listStyle(.plain)
|
||||||
|
.modifier(ScrollDismissesKeyboardModifier())
|
||||||
.simultaneousGesture(searchBarGesture)
|
.simultaneousGesture(searchBarGesture)
|
||||||
|
.simultaneousGesture(tapToDismissKeyboardGesture)
|
||||||
// .safeAreaInset(edge: .top) {
|
// .safeAreaInset(edge: .top) {
|
||||||
// VStack(spacing: 0) {
|
// VStack(spacing: 0) {
|
||||||
// searchBar
|
// searchBar
|
||||||
@ -193,6 +198,12 @@ struct ChatsTab: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var tapToDismissKeyboardGesture: some Gesture {
|
||||||
|
TapGesture().onEnded {
|
||||||
|
dismissKeyboard()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private var isSearching: Bool {
|
private var isSearching: Bool {
|
||||||
!searchText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
|
!searchText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
|
||||||
}
|
}
|
||||||
@ -286,6 +297,24 @@ struct ChatsTab: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private extension ChatsTab {
|
||||||
|
func dismissKeyboard() {
|
||||||
|
#if canImport(UIKit)
|
||||||
|
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct ScrollDismissesKeyboardModifier: ViewModifier {
|
||||||
|
func body(content: Content) -> some View {
|
||||||
|
if #available(iOS 16.0, *) {
|
||||||
|
content.scrollDismissesKeyboard(.interactively)
|
||||||
|
} else {
|
||||||
|
content
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private struct ChatRowView: View {
|
private struct ChatRowView: View {
|
||||||
let chat: PrivateChatListItem
|
let chat: PrivateChatListItem
|
||||||
let currentUserId: String?
|
let currentUserId: String?
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user