Skip to content

Instantly share code, notes, and snippets.

@Aakashcs
Created July 16, 2020 00:22
Show Gist options
  • Save Aakashcs/0b5c9713057fb8ffdf84422d59eb8d28 to your computer and use it in GitHub Desktop.
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
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