Created
July 16, 2020 00:22
-
-
Save Aakashcs/0b5c9713057fb8ffdf84422d59eb8d28 to your computer and use it in GitHub Desktop.
Resigning the keyboard on drag in the list can be realised using a method on UIApplication window. For easier handling I created an extension on UIApplication and view modifier for this extension and finally an extension to View
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
extension UIApplication { | |
func endEditing(_ force: Bool) { | |
self.windows | |
.filter{$0.isKeyWindow} | |
.first? | |
.endEditing(force) | |
} | |
} | |
struct ResignKeyboardOnDragGesture: ViewModifier { | |
var gesture = DragGesture().onChanged{_ in | |
UIApplication.shared.endEditing(true) | |
} | |
func body(content: Content) -> some View { | |
content.gesture(gesture) | |
} | |
} | |
extension View { | |
func resignKeyboardOnDragGesture() -> some View { | |
return modifier(ResignKeyboardOnDragGesture()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment