From 3769774e16b76e17094948d63c163f62dd11ecb5 Mon Sep 17 00:00:00 2001 From: Kieran Brown Date: Sat, 2 May 2020 10:19:18 -0400 Subject: [PATCH] Fix for Y direction issue of RSlider on macOS --- Sources/Sliders/RadialSlider.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sources/Sliders/RadialSlider.swift b/Sources/Sliders/RadialSlider.swift index b4944e0..ebd7e23 100644 --- a/Sources/Sliders/RadialSlider.swift +++ b/Sources/Sliders/RadialSlider.swift @@ -233,6 +233,19 @@ public struct RSlider: View { private func makeThumb(_ proxy: GeometryProxy) -> some View { let radius = min(proxy.size.height, proxy.size.width)/2 let middle = CGPoint(x: proxy.frame(in: .global).midX, y: proxy.frame(in: .global).midY) + #if os(macOS) + let gesture = DragGesture(minimumDistance: 0) + .onChanged { (value) in + let direction = self.calculateDirection(middle, value.location) + self.value = direction*(self.range.upperBound-self.range.lowerBound) + self.range.lowerBound + self.isActive = true + } + .onEnded { (value) in + let direction = self.calculateDirection(middle, value.location) + self.value = direction*(self.range.upperBound-self.range.lowerBound) + self.range.lowerBound + self.isActive = false + } + #else let gesture = DragGesture(minimumDistance: 0, coordinateSpace: .global) .onChanged { (value) in let direction = self.calculateDirection(middle, value.location) @@ -244,6 +257,7 @@ public struct RSlider: View { self.value = direction*(self.range.upperBound-self.range.lowerBound) + self.range.lowerBound self.isActive = false } + #endif let pct = (value-range.lowerBound)/(range.upperBound-range.lowerBound) let pX = radius*CGFloat(cos(pct*2 * .pi )) let pY = radius*CGFloat(sin(pct*2 * .pi ))