From 9f0c1eece880990b844a683058a8deb1bfdc97a9 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 5 May 2021 17:46:41 -0400 Subject: [PATCH] Add haptic feedback to poll voting --- Tusker/Views/Poll/PollOptionsView.swift | 10 ++++++++++ Tusker/Views/Poll/StatusPollView.swift | 2 ++ 2 files changed, 12 insertions(+) diff --git a/Tusker/Views/Poll/PollOptionsView.swift b/Tusker/Views/Poll/PollOptionsView.swift index d6442f18..e979d12d 100644 --- a/Tusker/Views/Poll/PollOptionsView.swift +++ b/Tusker/Views/Poll/PollOptionsView.swift @@ -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 diff --git a/Tusker/Views/Poll/StatusPollView.swift b/Tusker/Views/Poll/StatusPollView.swift index d24d216c..dd5d3bc2 100644 --- a/Tusker/Views/Poll/StatusPollView.swift +++ b/Tusker/Views/Poll/StatusPollView.swift @@ -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 {