From 3d45aa357ed84fbd0a206b319455ca96849a5204 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Mon, 6 Feb 2023 21:51:57 +0100 Subject: [PATCH] Dismiss keyboard interactively --- Backports/ScrollDismissesKeyboard+Backport.swift | 10 +++++++++- Shared/Search/SearchView.swift | 2 +- Shared/Settings/SettingsView.swift | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Backports/ScrollDismissesKeyboard+Backport.swift b/Backports/ScrollDismissesKeyboard+Backport.swift index 1e602d59..8f60cae6 100644 --- a/Backports/ScrollDismissesKeyboard+Backport.swift +++ b/Backports/ScrollDismissesKeyboard+Backport.swift @@ -2,11 +2,19 @@ import Foundation import SwiftUI extension Backport where Content: View { - @ViewBuilder func scrollDismissesKeyboard() -> some View { + @ViewBuilder func scrollDismissesKeyboardImmediately() -> some View { if #available(iOS 16.0, macOS 13.0, tvOS 16.0, *) { content.scrollDismissesKeyboard(.immediately) } else { content } } + + @ViewBuilder func scrollDismissesKeyboardInteractively() -> some View { + if #available(iOS 16.0, macOS 13.0, tvOS 16.0, *) { + content.scrollDismissesKeyboard(.interactively) + } else { + content + } + } } diff --git a/Shared/Search/SearchView.swift b/Shared/Search/SearchView.swift index 1c30b264..f5533258 100644 --- a/Shared/Search/SearchView.swift +++ b/Shared/Search/SearchView.swift @@ -50,7 +50,7 @@ struct SearchView: View { } } .backport - .scrollDismissesKeyboard() + .scrollDismissesKeyboardInteractively() #else ZStack { results diff --git a/Shared/Settings/SettingsView.swift b/Shared/Settings/SettingsView.swift index e7624fe7..d3034562 100644 --- a/Shared/Settings/SettingsView.swift +++ b/Shared/Settings/SettingsView.swift @@ -29,7 +29,7 @@ struct SettingsView: View { .alert(isPresented: $model.presentingAlert) { model.alert } #if os(iOS) .backport - .scrollDismissesKeyboard() + .scrollDismissesKeyboardInteractively() #endif }