Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public struct HorizontalRangeSliderStyle<Track: View, LowerThumb: View, UpperThu
let upperThumbInteractiveSize: CGSize

private let options: RangeSliderOptions

let onSelectLower: () -> Void
let onSelectUpper: () -> Void

public func makeBody(configuration: Self.Configuration) -> some View {
GeometryReader { geometry in
Expand Down Expand Up @@ -42,9 +45,15 @@ public struct HorizontalRangeSliderStyle<Track: View, LowerThumb: View, UpperThu
),
y: geometry.size.height / 2
)
.onTapGesture {
self.onSelectLower()
}
.gesture(
DragGesture()
.onChanged { gestureValue in

self.onSelectLower()

if configuration.dragOffset.wrappedValue == nil {
configuration.dragOffset.wrappedValue = gestureValue.startLocation.x - distanceFrom(
value: configuration.range.wrappedValue.lowerBound,
Expand Down Expand Up @@ -95,9 +104,15 @@ public struct HorizontalRangeSliderStyle<Track: View, LowerThumb: View, UpperThu
),
y: geometry.size.height / 2
)
.onTapGesture {
self.onSelectUpper()
}
.gesture(
DragGesture()
.onChanged { gestureValue in

self.onSelectUpper()

if configuration.dragOffset.wrappedValue == nil {
configuration.dragOffset.wrappedValue = gestureValue.startLocation.x - distanceFrom(
value: configuration.range.wrappedValue.upperBound,
Expand Down Expand Up @@ -139,7 +154,9 @@ public struct HorizontalRangeSliderStyle<Track: View, LowerThumb: View, UpperThu
.frame(minHeight: max(self.lowerThumbInteractiveSize.height, self.upperThumbInteractiveSize.height))
}

public init(track: Track, lowerThumb: LowerThumb, upperThumb: UpperThumb, lowerThumbSize: CGSize = CGSize(width: 27, height: 27), upperThumbSize: CGSize = CGSize(width: 27, height: 27), lowerThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), upperThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), options: RangeSliderOptions = .defaultOptions) {
public init(track: Track, lowerThumb: LowerThumb, upperThumb: UpperThumb, lowerThumbSize: CGSize = CGSize(width: 27, height: 27), upperThumbSize: CGSize = CGSize(width: 27, height: 27), lowerThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), upperThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), options: RangeSliderOptions = .defaultOptions,
onSelectLower: @escaping () -> Void = {},
onSelectUpper: @escaping () -> Void = {}) {
self.track = track
self.lowerThumb = lowerThumb
self.upperThumb = upperThumb
Expand All @@ -148,11 +165,15 @@ public struct HorizontalRangeSliderStyle<Track: View, LowerThumb: View, UpperThu
self.lowerThumbInteractiveSize = lowerThumbInteractiveSize
self.upperThumbInteractiveSize = upperThumbInteractiveSize
self.options = options
self.onSelectLower = onSelectLower
self.onSelectUpper = onSelectUpper
}
}

extension HorizontalRangeSliderStyle where Track == DefaultHorizontalRangeTrack {
public init(lowerThumb: LowerThumb, upperThumb: UpperThumb, lowerThumbSize: CGSize = CGSize(width: 27, height: 27), upperThumbSize: CGSize = CGSize(width: 27, height: 27), lowerThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), upperThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), options: RangeSliderOptions = .defaultOptions) {
public init(lowerThumb: LowerThumb, upperThumb: UpperThumb, lowerThumbSize: CGSize = CGSize(width: 27, height: 27), upperThumbSize: CGSize = CGSize(width: 27, height: 27), lowerThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), upperThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), options: RangeSliderOptions = .defaultOptions,
onSelectLower: @escaping () -> Void = {},
onSelectUpper: @escaping () -> Void = {}) {
self.track = DefaultHorizontalRangeTrack()
self.lowerThumb = lowerThumb
self.upperThumb = upperThumb
Expand All @@ -161,11 +182,16 @@ extension HorizontalRangeSliderStyle where Track == DefaultHorizontalRangeTrack
self.lowerThumbInteractiveSize = lowerThumbInteractiveSize
self.upperThumbInteractiveSize = upperThumbInteractiveSize
self.options = options
self.onSelectLower = onSelectLower
self.onSelectUpper = onSelectUpper

}
}

extension HorizontalRangeSliderStyle where LowerThumb == DefaultThumb, UpperThumb == DefaultThumb {
public init(track: Track, lowerThumbSize: CGSize = CGSize(width: 27, height: 27), upperThumbSize: CGSize = CGSize(width: 27, height: 27), lowerThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), upperThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), options: RangeSliderOptions = .defaultOptions) {
public init(track: Track, lowerThumbSize: CGSize = CGSize(width: 27, height: 27), upperThumbSize: CGSize = CGSize(width: 27, height: 27), lowerThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), upperThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), options: RangeSliderOptions = .defaultOptions,
onSelectLower: @escaping () -> Void = {},
onSelectUpper: @escaping () -> Void = {}) {
self.track = track
self.lowerThumb = DefaultThumb()
self.upperThumb = DefaultThumb()
Expand All @@ -174,11 +200,16 @@ extension HorizontalRangeSliderStyle where LowerThumb == DefaultThumb, UpperThum
self.lowerThumbInteractiveSize = lowerThumbInteractiveSize
self.upperThumbInteractiveSize = upperThumbInteractiveSize
self.options = options
self.onSelectLower = onSelectLower
self.onSelectUpper = onSelectUpper

}
}

extension HorizontalRangeSliderStyle where LowerThumb == DefaultThumb, UpperThumb == DefaultThumb, Track == DefaultHorizontalRangeTrack {
public init(lowerThumbSize: CGSize = CGSize(width: 27, height: 27), upperThumbSize: CGSize = CGSize(width: 27, height: 27), lowerThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), upperThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), options: RangeSliderOptions = .defaultOptions) {
public init(lowerThumbSize: CGSize = CGSize(width: 27, height: 27), upperThumbSize: CGSize = CGSize(width: 27, height: 27), lowerThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), upperThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), options: RangeSliderOptions = .defaultOptions,
onSelectLower: @escaping () -> Void = {},
onSelectUpper: @escaping () -> Void = {}) {
self.track = DefaultHorizontalRangeTrack()
self.lowerThumb = DefaultThumb()
self.upperThumb = DefaultThumb()
Expand All @@ -187,6 +218,8 @@ extension HorizontalRangeSliderStyle where LowerThumb == DefaultThumb, UpperThum
self.lowerThumbInteractiveSize = lowerThumbInteractiveSize
self.upperThumbInteractiveSize = upperThumbInteractiveSize
self.options = options
self.onSelectLower = onSelectLower
self.onSelectUpper = onSelectUpper
}
}

Expand Down