Created
November 27, 2019 16:25
-
-
Save perlguy99/517d27fca15e574e12dbee5e97a928b1 to your computer and use it in GitHub Desktop.
Dismissing Keyboard View Modifier
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
// | |
// DismissingKeyboard+ViewModifier.swift | |
// | |
// Created by Michalski (US), James B on 11/27/19. | |
// Copyright © 2019 Brent Michalski. All rights reserved. | |
// | |
import SwiftUI | |
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
This version seems to swallow up all events. Still testing.