another.im-ios/ConversationsClassic/View/UIToolkit/KeyboardDisposableModifier.swift
2024-06-19 17:15:27 +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))
}
}