From 74a30d27e830446fe1c07f30703dfe112a1849c1 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 6 Jan 2021 19:16:57 -0500 Subject: [PATCH] Hide keyboard before dismissing windows --- Tusker/Extensions/UIWindowSceneDelegate+Close.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Tusker/Extensions/UIWindowSceneDelegate+Close.swift b/Tusker/Extensions/UIWindowSceneDelegate+Close.swift index 75dde0a2..712164a8 100644 --- a/Tusker/Extensions/UIWindowSceneDelegate+Close.swift +++ b/Tusker/Extensions/UIWindowSceneDelegate+Close.swift @@ -12,6 +12,13 @@ extension UIWindowSceneDelegate { func closeWindow(animation: UIWindowScene.DismissalAnimation = .standard, errorHandler: ((Error) -> Void)? = nil) { guard let session = self.window??.windowScene?.session else { return } + // Hide the keyboard before dismissing window. + // Calling resignFirstResponder() on the window does not work (always returns false). + // Using UIApplication.shared.sendAction(#selector(resignFirstResponder), to: nil, from: nil, for: nil) + // may not work as desired if the window with focus is not the one being dismissed (in which case it's okay + // if the keyboard remains visible). + window??.endEditing(true) + let options = UIWindowSceneDestructionRequestOptions() options.windowDismissalAnimation = animation UIApplication.shared.requestSceneSessionDestruction(session, options: options, errorHandler: errorHandler)