mirror of
git://jb55.com/damus
synced 2024-09-19 19:46:51 +00:00
bf7120dc08
Changelog-Added: Add password autofill on account login and creation Closes: #559
41 lines
845 B
Swift
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)
|
|
}
|