23 lines
585 B
Swift
23 lines
585 B
Swift
|
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))
|
||
|
}
|
||
|
}
|