another.im-ios/old/View/UIToolkit/KeyboardDisposableModifier.swift
2024-08-11 13:09:29 +02:00

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))
}
}