Skip to content

Commit

Permalink
remove dependency on outdated AvailableHapticFeedback
Browse files Browse the repository at this point in the history
  • Loading branch information
yonat committed Apr 10, 2024
1 parent 62afa11 commit d5529aa
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 21 deletions.
4 changes: 0 additions & 4 deletions Example/MultiSliderDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,11 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-MultiSliderTests/Pods-MultiSliderTests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/AvailableHapticFeedback/AvailableHapticFeedback.framework",
"${BUILT_PRODUCTS_DIR}/MultiSlider/MultiSlider.framework",
"${BUILT_PRODUCTS_DIR}/SweeterSwift/SweeterSwift.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AvailableHapticFeedback.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MultiSlider.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SweeterSwift.framework",
);
Expand Down Expand Up @@ -291,13 +289,11 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-MultiSliderDemo/Pods-MultiSliderDemo-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/AvailableHapticFeedback/AvailableHapticFeedback.framework",
"${BUILT_PRODUCTS_DIR}/MultiSlider/MultiSlider.framework",
"${BUILT_PRODUCTS_DIR}/SweeterSwift/SweeterSwift.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AvailableHapticFeedback.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MultiSlider.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SweeterSwift.framework",
);
Expand Down
10 changes: 3 additions & 7 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
PODS:
- AvailableHapticFeedback (1.0.2)
- MultiSlider (2.1.0):
- AvailableHapticFeedback
- MultiSlider (2.1.3):
- SweeterSwift
- SweeterSwift (1.2.1)
- SwiftFormat/CLI (0.50.7)
Expand All @@ -16,7 +14,6 @@ DEPENDENCIES:

SPEC REPOS:
trunk:
- AvailableHapticFeedback
- SweeterSwift
- SwiftFormat
- SwiftLint
Expand All @@ -33,13 +30,12 @@ CHECKOUT OPTIONS:
:git: https://github.com/yonat/SwiftQuality

SPEC CHECKSUMS:
AvailableHapticFeedback: 9b21b9f6d3e4566015988b5de35b40abefe6c09a
MultiSlider: ac3545e486dcf7f758848679cc601a5581da8d26
MultiSlider: eec43a6f41342001f5cabc698055ce3bdee4c711
SweeterSwift: 61baeda1c0c27d1dc57c8112c3d6a82e5aff3139
SwiftFormat: 4fcf72ee44c7198255108c22ed7135c38a36ba6b
SwiftLint: 77f7cb2b9bb81ab4a12fcc86448ba3f11afa50c6
SwiftQuality: 8d69820e0f82a25563c3cb33d31b0a11f124ea0c

PODFILE CHECKSUM: ed7f9205bad8b43d16383ee943568b2a6adc7775

COCOAPODS: 1.12.1
COCOAPODS: 1.15.2
1 change: 0 additions & 1 deletion MultiSlider.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Pod::Spec.new do |s|
s.resources = ['PrivacyInfo.xcprivacy']

s.dependency 'SweeterSwift'
s.dependency 'AvailableHapticFeedback'

s.pod_target_xcconfig = { 'LD_RUNPATH_SEARCH_PATHS' => '$(FRAMEWORK_SEARCH_PATHS)' } # fix Interface Builder render error

Expand Down
3 changes: 1 addition & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/yonat/SweeterSwift", from: "1.0.4"),
.package(url: "https://github.com/yonat/AvailableHapticFeedback", from: "1.0.2"),
],
targets: [
.target(name: "MultiSlider", dependencies: ["SweeterSwift", "AvailableHapticFeedback"], path: "Sources", resources: [.copy("PrivacyInfo.xcprivacy")]),
.target(name: "MultiSlider", dependencies: ["SweeterSwift"], path: "Sources", resources: [.copy("PrivacyInfo.xcprivacy")]),
],
swiftLanguageVersions: [.v5]
)
6 changes: 2 additions & 4 deletions Sources/MultiSlider+Drag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ extension MultiSlider: UIGestureRecognizerDelegate {
@objc open func didDrag(_ panGesture: UIPanGestureRecognizer) {
switch panGesture.state {
case .began:
if isHapticSnap { selectionFeedbackGenerator.prepare() }
// determine thumb to drag
let location = panGesture.location(in: slideView)
draggedThumbIndex = closestThumb(point: location)
case .ended, .cancelled, .failed:
if isHapticSnap { selectionFeedbackGenerator.end() }
sendActions(for: .touchUpInside) // no bounds check for now (.touchUpInside vs .touchUpOutside)
if !isContinuous { sendActions(for: [.valueChanged, .primaryActionTriggered]) }
default:
Expand Down Expand Up @@ -80,8 +78,8 @@ extension MultiSlider: UIGestureRecognizerDelegate {
isSettingValue = true
value[draggedThumbIndex] = newValue
isSettingValue = false
if (isHapticSnap && (snap != .never)) || relativeValue == 0 || relativeValue == 1 {
selectionFeedbackGenerator.generateFeedback()
if snap != .never || relativeValue == 0 || relativeValue == 1 {
selectionFeedbackGenerator?.selectionChanged()
}
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 @@ -26,6 +26,8 @@ extension MultiSlider {
if #available(iOS 11.0, *) {
valueLabelFormatter.addObserverForAllProperties(observer: self)
}

selectionFeedbackGenerator = UISelectionFeedbackGenerator()
}

private func setupPanGesture() {
Expand Down
13 changes: 10 additions & 3 deletions Sources/MultiSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Copyright © 2016 Yonat Sharon. All rights reserved.
//

import AvailableHapticFeedback
import SweeterSwift
import UIKit

Expand Down Expand Up @@ -149,7 +148,15 @@ open class MultiSlider: UIControl {
}

/// generate haptic feedback when hitting snap steps
@IBInspectable open dynamic var isHapticSnap: Bool = true
@IBInspectable open dynamic var isHapticSnap: Bool {
get {
selectionFeedbackGenerator != nil
}
set {
selectionFeedbackGenerator = newValue ? UISelectionFeedbackGenerator() : nil
selectionFeedbackGenerator?.prepare()
}
}

// MARK: - Value Labels

Expand Down Expand Up @@ -325,7 +332,7 @@ open class MultiSlider: UIControl {
let margin: CGFloat = 32
var isSettingValue = false
lazy var defaultThumbImage: UIImage? = .circle()
var selectionFeedbackGenerator = AvailableHapticFeedback()
var selectionFeedbackGenerator: UISelectionFeedbackGenerator?

// MARK: - Overrides

Expand Down

0 comments on commit d5529aa

Please sign in to comment.