HapticFeedbackClient
is a dependency (see swift-dependencies) that allows to generate haptics in a centralized and testable way.
The client can be used in reducers to create haptic feedbacks when processing actions.
@Reducer
struct Feature {
...
@Dependency(\.hapticFeedbackClient)
var haptics
var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
case .didScrollDateWheel:
haptics.perform(.selection)
return .none
}
}
}
...
}
You can add the library to an Xcode project by adding it as a package dependency.
If you want to use the library in a SwiftPM project, it's as simple as adding it to a dependencies
clause in your Package.swift
:
dependencies: [
.package(url: "https://github.com/whutao/swift-composable-haptics", from: "1.0.0")
]
All modules are released under the MIT license. See LICENSE for details.