Created
February 8, 2020 21:44
-
-
Save dfrobison/4759c9920ef1a583c780bb74154c2279 to your computer and use it in GitHub Desktop.
[Dismissing the keyboard] One way to dismiss the keyboard given that the tapGesture is not overwritten somewhere else
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct DismissingKeyboard: ViewModifier { | |
func body(content: Content) -> some View { | |
content | |
.onTapGesture { | |
let keyWindow = UIApplication.shared.connectedScenes | |
.filter({$0.activationState == .foregroundActive}) | |
.map({$0 as? UIWindowScene}) | |
.compactMap({$0}) | |
.first?.windows | |
.filter({$0.isKeyWindow}).first | |
keyWindow?.endEditing(true) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment