From 720582ed70a302b41fb9a78401509cbf18b9d13f Mon Sep 17 00:00:00 2001 From: Tim Schmitz Date: Fri, 27 Oct 2023 11:39:24 -0400 Subject: [PATCH] Allow trackpad swipe to scroll in Catalyst apps --- Source/Charts/Charts/BarLineChartViewBase.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Source/Charts/Charts/BarLineChartViewBase.swift b/Source/Charts/Charts/BarLineChartViewBase.swift index 343cd6832f..14a97a6fdc 100644 --- a/Source/Charts/Charts/BarLineChartViewBase.swift +++ b/Source/Charts/Charts/BarLineChartViewBase.swift @@ -128,6 +128,14 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD _panGestureRecognizer.delegate = self + // Allow trackpad swipe to scroll in Catalyst apps + #if targetEnvironment(macCatalyst) + if #available(iOS 13.4, macCatalyst 13.4, *) { + _panGestureRecognizer.allowedScrollTypesMask = .all + } + _panGestureRecognizer.maximumNumberOfTouches = 0 + #endif + self.addGestureRecognizer(_tapGestureRecognizer) self.addGestureRecognizer(_doubleTapGestureRecognizer) self.addGestureRecognizer(_panGestureRecognizer) @@ -677,7 +685,13 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD @objc private func panGestureRecognized(_ recognizer: NSUIPanGestureRecognizer) { - if recognizer.state == NSUIGestureRecognizerState.began && recognizer.nsuiNumberOfTouches() > 0 + // Allow trackpad swipe to scroll in Catalyst apps + #if targetEnvironment(macCatalyst) + let isBeginning = recognizer.state == NSUIGestureRecognizerState.began + #else + let isBeginning = recognizer.state == NSUIGestureRecognizerState.began && recognizer.nsuiNumberOfTouches() > 0 + #endif + if isBeginning { stopDeceleration()