1
0
mirror of git://jb55.com/damus synced 2024-09-19 19:46:51 +00:00
damus/damus/Util/InputDismissKeyboard.swift
Terry Yiu bf7120dc08 Add password autofill on account login and creation
Changelog-Added: Add password autofill on account login and creation
Closes: #559
2023-02-10 10:14:44 -08:00

41 lines
845 B
Swift

//
// InputDismissKeyboard.swift
// damus
//
// Created by William Casarin on 2022-07-02.
//
import Foundation
import SwiftUI
public extension View {
func dismissKeyboardOnTap() -> some View {
modifier(DismissKeyboardOnTap())
}
}
public struct DismissKeyboardOnTap: ViewModifier {
public func body(content: Content) -> some View {
#if os(macOS)
return content
#else
return content.gesture(tapGesture)
#endif
}
private var tapGesture: some Gesture {
TapGesture().onEnded(end_editing)
}
}
public func end_editing() {
UIApplication.shared.connectedScenes
.filter {$0.activationState == .foregroundActive}
.map {$0 as? UIWindowScene}
.compactMap({$0})
.first?.windows
.filter {$0.isKeyWindow}
.first?.endEditing(true)
}