-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
336fe80
commit a42d6d5
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
Sources/ACKategories/SwiftUIExtensions/View+endEditingOnTap.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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?() | ||
} | ||
} | ||
} |