From a32f417776f52e83cdab2a5378be928d5748b395 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Tue, 20 Dec 2022 23:41:21 +0100 Subject: [PATCH] Throttle controls bar gestures --- Shared/Views/ControlsBar.swift | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Shared/Views/ControlsBar.swift b/Shared/Views/ControlsBar.swift index a7a66318..8745a730 100644 --- a/Shared/Views/ControlsBar.swift +++ b/Shared/Views/ControlsBar.swift @@ -13,6 +13,8 @@ struct ControlsBar: View { @State private var shareURL: URL? @Binding var expansionState: ExpansionState + @State internal var gestureThrottle = Throttle(interval: 0.25) + var presentingControls = true var backgroundEnabled = true var borderTop = true @@ -244,18 +246,20 @@ struct ControlsBar: View { } func gestureAction(_ action: PlayerTapGestureAction) { - switch action { - case .togglePlayer: - model.togglePlayer() - case .openChannel: - guard let channel = model.videoForDisplay?.channel else { return } - navigation.openChannel(channel, navigationStyle: navigationStyle) - case .togglePlayerVisibility: - withAnimation(.spring(response: 0.25)) { - expansionState = expansionState == .full ? .mini : .full + gestureThrottle.execute { + switch action { + case .togglePlayer: + self.model.togglePlayer() + case .openChannel: + guard let channel = self.model.videoForDisplay?.channel else { return } + self.navigation.openChannel(channel, navigationStyle: self.navigationStyle) + case .togglePlayerVisibility: + withAnimation(.spring(response: 0.25)) { + self.expansionState = self.expansionState == .full ? .mini : .full + } + default: + return } - default: - return } } #endif