Add haptic feedback to poll voting

This commit is contained in:
Shadowfacts 2021-05-05 17:46:41 -04:00
parent e18a09f4ac
commit 9f0c1eece8
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 12 additions and 0 deletions

View File

@ -26,6 +26,8 @@ class PollOptionsView: UIControl {
private let animationDuration: TimeInterval = 0.1
private let scaledTransform = CGAffineTransform(scaleX: 0.95, y: 0.95)
private let generator = UIImpactFeedbackGenerator(style: .soft)
override var isEnabled: Bool {
didSet {
options.forEach { $0.checkbox.readOnly = !isEnabled }
@ -106,6 +108,9 @@ class PollOptionsView: UIControl {
}
animator.startAnimation()
generator.impactOccurred()
generator.prepare()
return true
}
}
@ -130,6 +135,11 @@ class PollOptionsView: UIControl {
view.transform = index == newIndex ? self.scaledTransform : .identity
}
}
if newIndex != nil {
generator.impactOccurred()
generator.prepare()
}
}
return true

View File

@ -136,6 +136,8 @@ class StatusPollView: UIView {
voteButton.isEnabled = false
voteButton.setTitle("Voted", for: .disabled)
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
let request = Poll.vote(poll.id, choices: optionsView.checkedOptionIndices)
mastodonController.run(request) { (response) in
switch response {