diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e1fa2a..a841e52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ ## Next +- Add SwiftUI extension `View+endEditingOnTap` ([#152](https://github.com/AckeeCZ/ACKategories/pull/152), kudos to @lukashromadnik) + ## 6.15.0 - SwiftUI improvements ([#149](https://github.com/AckeeCZ/ACKategories/pull/149), kudos to @olejnjak) diff --git a/Sources/ACKategories/SwiftUIExtensions/View+endEditingOnTap.swift b/Sources/ACKategories/SwiftUIExtensions/View+endEditingOnTap.swift new file mode 100644 index 0000000..468e773 --- /dev/null +++ b/Sources/ACKategories/SwiftUIExtensions/View+endEditingOnTap.swift @@ -0,0 +1,20 @@ +import SwiftUI + +@available(iOS 13.0, *) +public extension View { + + @available(iOSApplicationExtension, unavailable) + func endEditingOnTap( + _ action: (() -> Void)? = nil + ) -> some View { + onTapGesture { + UIApplication.shared.sendAction( + #selector(UIResponder.resignFirstResponder), + to: nil, + from: nil, + for: nil + ) + action?() + } + } +}