https://github.com/efremidze/Haptica
Easy Haptic Feedback Generator ๐ณ
https://github.com/efremidze/Haptica
apple carthage cocoapods feedback generator haptic ios ios10 notes patterns swift taptic uibutton vibrate
Last synced: 3 months ago
JSON representation
Easy Haptic Feedback Generator ๐ณ
- Host: GitHub
- URL: https://github.com/efremidze/Haptica
- Owner: efremidze
- License: mit
- Created: 2017-03-31T22:09:07.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-08-28T01:25:50.000Z (about 3 years ago)
- Last Synced: 2024-11-29T03:18:35.795Z (11 months ago)
- Topics: apple, carthage, cocoapods, feedback, generator, haptic, ios, ios10, notes, patterns, swift, taptic, uibutton, vibrate
- Language: Swift
- Homepage:
- Size: 703 KB
- Stars: 774
- Watchers: 10
- Forks: 42
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-swift - Haptica - Easy Haptic Feedback Generator. (Libs / Hardware)
- awesome-swift - Haptica - Easy Haptic Feedback Generator. (Libs / Hardware)
- awesome-ios-star - Haptica - Easy Haptic Feedback Generator. (UI / Font)
- fucking-awesome-swift - Haptica - Easy Haptic Feedback Generator. (Libs / Hardware)
- awesome-ios - Haptica - Easy Haptic Feedback Generator. (UI / Font)
- awesome-swift - Haptica - Easy Haptic Feedback Generator ` ๐ 2 years ago` (Hardware [๐](#readme))
README

[](https://github.com/efremidze/Haptica/actions/workflows/ci.yml)
[](https://cocoapods.org/pods/Haptica)
[](https://github.com/Carthage/Carthage)
[](https://swift.org/package-manager/)
[](https://swift.org)
[](https://github.com/efremidze/Haptica/blob/master/LICENSE)
# Haptica
**Haptica** is a simple and expressive haptic feedback generator for iOS.
```bash
$ pod try Haptica
```
---
## ๐ฑ Requirements
| Haptica Version | iOS | Swift | Xcode |
|-----------------|-----|-------|--------|
| 4.x | 13+ | 5.x | 11+ |
| 3.x | 9+ | 5.x | 8+ |
| 2.x | 9+ | 4.x | 8+ |
| 1.x | 9+ | 3.x | 8+ |
### Haptic Feedback Requirements
- Device with a supported Taptic Engine
- App running in the foreground
- System Haptics setting enabled
---
## ๐ Usage
Trigger a haptic feedback with a single line:
```swift
Haptic.impact(.light).generate()
```
### Feedback Types
- **Impact** (`.light`, `.medium`, `.heavy`, `.soft`, `.rigid`)
Use to indicate collision or snap-to-position.
- **Notification** (`.success`, `.warning`, `.error`)
Use to communicate task results.
- **Selection**
Use for navigation through discrete values.
### Semantic Types (New)
Use new expressive variants for common interactions:
```swift
Haptic.success.generate()
Haptic.warning.generate()
Haptic.start.generate()
Haptic.stop.generate()
Haptic.increase.generate()
Haptic.decrease.generate()
```
These semantic styles internally map to appropriate UIKit or Core Haptics-based effects.
### Custom Vibration Patterns
```swift
Haptic.play("..oO-Oo..", delay: 0.1)
```
| Symbol | Feedback Type |
|--------|-----------------|
| `.` | Light impact |
| `o` | Medium impact |
| `O` | Heavy impact |
| `x` | Soft impact |
| `X` | Rigid impact |
| `-` | 0.1s pause |
Or use structured notes:
```swift
Haptic.play([
.haptic(.impact(.light)),
.haptic(.impact(.heavy)),
.wait(0.1),
.haptic(.impact(.heavy)),
.haptic(.impact(.light))
])
```
### ๐ง Core Haptics Support
Haptica uses **Core Haptics** by default when available. To use the legacy API:
```swift
Haptic.play(notes, legacy: true)
```
### ๐ Play from Pattern File (New) - iOS 16+
Play a Core Haptics pattern from a bundled `.ahap` file:
```swift
Haptic.playPattern(named: "Feedback")
```
Make sure the file is included in your app bundle and contains a valid haptic pattern.
---
## ๐งน UIButton Extension
Enable haptics for buttons easily:
```swift
button.isHaptic = true
button.hapticType = .impact(.light)
```
Add or remove haptic feedback on control events:
```swift
button.addHaptic(.selection, forControlEvents: .touchDown)
button.removeHaptic(forControlEvents: .touchDown)
```
**API Summary:**
```swift
var isHaptic: Bool
var hapticType: Haptic?
var hapticControlEvents: UIControl.Event?
func addHaptic(_ haptic: Haptic, forControlEvents events: UIControl.Event)
func removeHaptic(forControlEvents events: UIControl.Event)
```
---
## ๐ Sound Effects
Integrate sound feedback with [Peep](https://github.com/efremidze/Peep):
```swift
Peep.play(sound: KeyPress.tap)
```
---
## ๐ฆ Installation
### Swift Package Manager
```swift
// For iOS 13+
.package(url: "https://github.com/efremidze/Haptica.git", from: "4.0.0")
// For iOS 9
.package(url: "https://github.com/efremidze/Haptica.git", from: "3.0.0")
```
### CocoaPods
```ruby
use_frameworks!
pod "Haptica"
```
### Carthage
```ruby
github "efremidze/Haptica"
```
---
## ๐ฌ Communication
- Found a bug? โ [Open an issue](https://github.com/efremidze/Haptica/issues)
- Have a feature request? โ [Open an issue](https://github.com/efremidze/Haptica/issues)
- Want to contribute? โ Submit a pull request
---
## ๐ฐ Mentions
- [Fresh Swift](http://freshswift.net/post/-kj8ocn5j9lt_ljpffm4/)
---
## ๐ License
Haptica is available under the MIT license. See the [LICENSE](./LICENSE) file for details.