Skip to content

Commit

Permalink
visionOS compile fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nighthawk committed May 1, 2024
1 parent ca64744 commit f3f6042
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/MultiSlider+Drag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ extension MultiSlider: UIGestureRecognizerDelegate {
isSettingValue = true
value[draggedThumbIndex] = newValue
isSettingValue = false

#if !os(visionOS)
if snap != .never || relativeValue == 0 || relativeValue == 1 {
selectionFeedbackGenerator?.selectionChanged()
}
#endif

if isContinuous { sendActions(for: [.valueChanged, .primaryActionTriggered]) }
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/MultiSlider+Internal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ extension MultiSlider {
valueLabelFormatter.addObserverForAllProperties(observer: self)
}

#if !os(visionOS)
selectionFeedbackGenerator = UISelectionFeedbackGenerator()
#endif
}

private func setupPanGesture() {
Expand Down
6 changes: 6 additions & 0 deletions Sources/MultiSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ open class MultiSlider: UIControl {
}
}

#if os(visionOS)
@IBInspectable open dynamic var isHapticSnap: Bool = false
#else
/// generate haptic feedback when hitting snap steps
@IBInspectable open dynamic var isHapticSnap: Bool {
get {
Expand All @@ -158,6 +161,7 @@ open class MultiSlider: UIControl {
selectionFeedbackGenerator?.prepare()
}
}
#endif

// MARK: - Value Labels

Expand Down Expand Up @@ -333,7 +337,9 @@ open class MultiSlider: UIControl {
let margin: CGFloat = 32
var isSettingValue = false
lazy var defaultThumbImage: UIImage? = .circle()
#if !os(visionOS)
var selectionFeedbackGenerator: UISelectionFeedbackGenerator?
#endif

// MARK: - Overrides

Expand Down

0 comments on commit f3f6042

Please sign in to comment.