another.im-ios/old/View/UIToolkit/KeyboardDisposableModifier.swift

23 lines
585 B
Swift
Raw Normal View History

2024-06-19 15:15:27 +00:00
import SwiftUI
private struct ContentBlockModifier<T: Hashable>: ViewModifier {
var focus: FocusState<T?>.Binding
func body(content: Content) -> some View {
content
.background {
Rectangle()
.foregroundColor(.white.opacity(0.01))
.onTapGesture {
focus.wrappedValue = nil
}
}
}
}
extension View {
func keyboardUnfocus<T>(_ focus: FocusState<T?>.Binding) -> some View {
self.modifier(ContentBlockModifier(focus: focus))
}
}