ersanq/haptickit
Haptic feedback in one line. No generators. No setup. No noise.
The Problem
// π Native API β 4 lines for a single tap
let generator = UIImpactFeedbackGenerator(style: .medium)
generator.prepare()
generator.impactOccurred()The Solution
// π HapticKit β 1 line
Haptic.impact()Features
- β
Haptic.impact()β light, medium, heavy, rigid, soft - β
Haptic.success()/.warning()/.error() - β
Haptic.selection()β for pickers and toggles - β
Haptic.custom(intensity: 0.75)β precise control - β
Haptic.sequence([...], delay:)β chain multiple haptics - β
SwiftUI modifiers β
.hapticFeedback(),.hapticSuccess(),.hapticError() - β Automatically disabled on iPad and non-haptic devices
- β
Zero dependencies β wraps native
UIFeedbackGenerator - β iOS 16+, watchOS 9+, visionOS 1+
Installation
https://github.com/ErsanQ/HapticKitOr in Package.swift:
.package(url: "https://github.com/ErsanQ/HapticKit", from: "1.0.0")Usage
Impact
Haptic.impact() // medium (default)
Haptic.impact(.light)
Haptic.impact(.heavy)
Haptic.impact(.rigid)
Haptic.impact(.soft)Notification
Haptic.success() // task completed β
Haptic.warning() // caution β οΈ
Haptic.error() // something went wrong βSelection
Haptic.selection() // great for pickers, sliders, tab barsCustom Intensity
Haptic.custom(intensity: 0.3) // subtle
Haptic.custom(intensity: 1.0) // maximumSequences
// Double tap
Haptic.sequence([.impact(.light), .impact(.heavy)], delay: 0.1)
// Success celebration
Haptic.sequence([
.impact(.light),
.impact(.medium),
.impact(.heavy),
.success
], delay: 0.08)SwiftUI Modifiers
// Trigger on value change
Toggle("Notifications", isOn: $isOn)
.hapticFeedback(.impact(.medium), trigger: isOn)
// On success
Button("Save") { save() }
.hapticSuccess(trigger: isSaved)
// On error
TextField("Email", text: $email)
.hapticError(trigger: hasError)
// On selection
Picker("Theme", selection: $theme) { ... }
.hapticSelection(trigger: theme)API Reference
Haptic
| Method | Description | |--------|-------------| | impact( style:) | Impact feedback (default: .medium) | | success() | Success notification | | warning() | Warning notification | | error() | Error notification | | notify( style:) | Notification with explicit style | | selection() | Selection changed | | custom(intensity:) | Impact at custom intensity (0.0β1.0) | | sequence(_ events:delay:) | Chain multiple haptics |
HapticEvent (for sequences)
.impact(.light/medium/heavy/rigid/soft) Β· .success Β· .warning Β· .error Β· .selection Β· .custom(intensity:)
Requirements
- iOS 16.0+ / watchOS 9.0+ / visionOS 1.0+
- Swift 5.9+
- Xcode 15.0+
License
HapticKit is available under the MIT license. See the LICENSE file for more info.
Package Metadata
Repository: ersanq/haptickit
Default branch: main
README: README.md