From e81cc2becfb4ad370549e9f2c6ab161b57e6b9b3 Mon Sep 17 00:00:00 2001 From: Alistair Pullen Date: Mon, 30 Sep 2024 21:22:09 +0000 Subject: [PATCH] feat: enhance click wheel rotation speed handling Co-authored-by: Genie --- DankPod/Screens/HomeViewController.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/DankPod/Screens/HomeViewController.swift b/DankPod/Screens/HomeViewController.swift index 48e2ed7..c14d976 100644 --- a/DankPod/Screens/HomeViewController.swift +++ b/DankPod/Screens/HomeViewController.swift @@ -13,6 +13,7 @@ class HomeViewController: UIViewController, ClickWheelProtocol { let tableView: UITableView = UITableView() var vcs: [UIViewController] = [MusicViewController(), MusicViewController(), MusicViewController(), MusicViewController(), MusicViewController(), MusicViewController(), PlaybackViewController()] + var lastRotationTime = Date() var counter: Int = 0 var hasSetupUI = false @@ -55,15 +56,24 @@ class HomeViewController: UIViewController, ClickWheelProtocol { func clickWheelDidRotate(rotationDirection: RotationDirection) { + let timeDiff = Date().timeIntervalSince(lastRotationTime) + let scrollSpeedThreshold = 0.1 + lastRotationTime = Date() if (rotationDirection == .CLOCKWISE) { if (counter + 1 <= self.menuItems.count - 1) { counter += 1 + if (timeDiff < scrollSpeedThreshold && counter + 1 <= self.menuItems.count - 1) { + counter += 1 + } let ip = IndexPath(row: counter, section: 0) tableView.selectRow(at: ip, animated: false, scrollPosition: .top) } } else { if (counter > 0) { counter -= 1 + if (timeDiff < scrollSpeedThreshold && counter > 0) { + counter -= 1 + } let ip = IndexPath(row: counter, section: 0) tableView.selectRow(at: ip, animated: false, scrollPosition: .top) }