Skip to content

ErsanQ/HapticKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HapticKit

Swift 5.9 iOS 16+ SPM compatible MIT License

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/HapticKit

Or 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 bars

Custom Intensity

Haptic.custom(intensity: 0.3)  // subtle
Haptic.custom(intensity: 1.0)  // maximum

Sequences

// 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.


Author

Built by Ersan Q Abo Esha@ErsanQ

If HapticKit saved you time, consider giving it a ⭐️ on GitHub.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages