Add haptic feedback to poll voting
This commit is contained in:
parent
e18a09f4ac
commit
9f0c1eece8
|
@ -26,6 +26,8 @@ class PollOptionsView: UIControl {
|
||||||
private let animationDuration: TimeInterval = 0.1
|
private let animationDuration: TimeInterval = 0.1
|
||||||
private let scaledTransform = CGAffineTransform(scaleX: 0.95, y: 0.95)
|
private let scaledTransform = CGAffineTransform(scaleX: 0.95, y: 0.95)
|
||||||
|
|
||||||
|
private let generator = UIImpactFeedbackGenerator(style: .soft)
|
||||||
|
|
||||||
override var isEnabled: Bool {
|
override var isEnabled: Bool {
|
||||||
didSet {
|
didSet {
|
||||||
options.forEach { $0.checkbox.readOnly = !isEnabled }
|
options.forEach { $0.checkbox.readOnly = !isEnabled }
|
||||||
|
@ -106,6 +108,9 @@ class PollOptionsView: UIControl {
|
||||||
}
|
}
|
||||||
animator.startAnimation()
|
animator.startAnimation()
|
||||||
|
|
||||||
|
generator.impactOccurred()
|
||||||
|
generator.prepare()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,6 +135,11 @@ class PollOptionsView: UIControl {
|
||||||
view.transform = index == newIndex ? self.scaledTransform : .identity
|
view.transform = index == newIndex ? self.scaledTransform : .identity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if newIndex != nil {
|
||||||
|
generator.impactOccurred()
|
||||||
|
generator.prepare()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -136,6 +136,8 @@ class StatusPollView: UIView {
|
||||||
voteButton.isEnabled = false
|
voteButton.isEnabled = false
|
||||||
voteButton.setTitle("Voted", for: .disabled)
|
voteButton.setTitle("Voted", for: .disabled)
|
||||||
|
|
||||||
|
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
|
||||||
|
|
||||||
let request = Poll.vote(poll.id, choices: optionsView.checkedOptionIndices)
|
let request = Poll.vote(poll.id, choices: optionsView.checkedOptionIndices)
|
||||||
mastodonController.run(request) { (response) in
|
mastodonController.run(request) { (response) in
|
||||||
switch response {
|
switch response {
|
||||||
|
|
Loading…
Reference in New Issue