Skip to content

Commit

Permalink
Merging Contributions (#34)
Browse files Browse the repository at this point in the history
* Swift tools version (#33)

* chore: swift-tools 5.3

* Update Package.swift

Co-authored-by: Bobby <[email protected]>
Co-authored-by: Bobby <[email protected]>

* removing accent color on macOS

* Measurement init (#35)

* added support for Measurement in ValueSlider

* made ValueSliderStyleConfiguration init public

Co-authored-by: skryshi <[email protected]>

* Slider `onSelect` callbacks (#36)

* evaluate VideoPlayer project

* on drag, select corresponding thumb control.

Co-authored-by: Andy Park <[email protected]>

* Update ci.yml

* Update ci.yml

Co-authored-by: Bobby <[email protected]>
Co-authored-by: Bobby <[email protected]>
Co-authored-by: skryshi <[email protected]>
Co-authored-by: Andy Park <[email protected]>
  • Loading branch information
5 people authored May 31, 2021
1 parent 7e8246d commit 1fcada2
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PackageDescription
let package = Package(
name: "Sliders",
platforms: [
.iOS(.v13), .macOS(.v10_15)
.iOS(.v14), .macOS(.v11)
],
products: [
.library(name: "Sliders", targets: ["Sliders"])
Expand Down
11 changes: 0 additions & 11 deletions Sources/Sliders/Base/AccentColor.swift

This file was deleted.

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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ public struct ValueSliderStyleConfiguration {
public let onEditingChanged: (Bool) -> Void
public var dragOffset: Binding<CGFloat?>

public init(value: Binding<CGFloat>, bounds: ClosedRange<CGFloat>, step: CGFloat, onEditingChanged: @escaping (Bool) -> Void, dragOffset: Binding<CGFloat?>) {
self.value = value
self.bounds = bounds
self.step = step
self.onEditingChanged = onEditingChanged
self.dragOffset = dragOffset
}

func with(dragOffset: Binding<CGFloat?>) -> Self {
var mutSelf = self
mutSelf.dragOffset = dragOffset
Expand Down
20 changes: 20 additions & 0 deletions Sources/Sliders/ValueSlider/ValueSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,23 @@ extension ValueSlider {
)
}
}

extension ValueSlider {
public init(value: Binding<Measurement<Unit>>, in bounds: ClosedRange<Measurement<Unit>>, step: Measurement<Unit>, onEditingChanged: @escaping (Bool) -> Void = { _ in }) {

self.init(
ValueSliderStyleConfiguration(
value: Binding(get: {
CGFloat(value.wrappedValue.value)
},
set: {
value.wrappedValue = Measurement<Unit>(value: Double($0), unit: value.wrappedValue.unit)
}),
bounds: CGFloat(bounds.lowerBound.value)...CGFloat(bounds.upperBound.value),
step: CGFloat(step.value),
onEditingChanged: onEditingChanged,
dragOffset: .constant(0)
)
)
}
}

0 comments on commit 1fcada2

Please sign in to comment.