Add a UINotificationFeedbackGenerator to Card views

This commit is contained in:
CypherPoet 2020-01-20 15:58:35 -06:00
parent 3a68dadae0
commit de76a64165
2 changed files with 7 additions and 1 deletions

View File

@ -95,12 +95,13 @@ I'm currently seeking freelance, remote opportunities as an iOS developer! If yo
- **Day 86:** [_Project 17: Flashzilla (Part One)_](./day-086/)
- **Day 87:** [_Project 17: Flashzilla (Part Two)_](./day-087/)
- **Day 88:** [_Project 17: Flashzilla (Part Three)_](./day-088/)
- **Day 89:** [_Project 17: Flashzilla (Part Four)_](./day-089/)
</details>
**Latest Day:**
- **Day 89:** [_Project 17: Flashzilla (Part Four)_](./day-089/)
- **Day 90:** [_Project 17: Flashzilla (Part Five)_](./day-090/)

View File

@ -22,6 +22,7 @@ struct DraggableCardView {
var onRemove: ((Card) -> Void)? = nil
@GestureState private var dragOffset = CGSize.zero
let feedbackGenerator = UINotificationFeedbackGenerator()
}
@ -97,10 +98,14 @@ extension DraggableCardView {
DragGesture(minimumDistance: 0)
.updating($dragOffset, body: { (newValue, offsetState, _) in
offsetState = newValue.translation
self.feedbackGenerator.prepare()
})
.onEnded { value in
if abs(value.translation.width) > self.distanceToDragForRemoval {
self.onRemove?(self.card)
self.feedbackGenerator.notificationOccurred(.success)
} else {
self.feedbackGenerator.notificationOccurred(.error)
}
}
}