• Stars
    star
    485
  • Rank 90,698 (Top 2 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 6 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Haptico πŸ“³ - easy to use haptic feedback generator with pattern-play support

Haptico

Haptico is easy to use iOS haptic feedback generator. Besides default haptic feedbacks it can play patterns! Checkout Example project.

CI Status Version License Platform

Table of contents

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

How to use

First of all you will need to import Haptico module into your class:

import Haptico

Also keep in mind that depending on the device you are using - the feedback might be different. Starting from iPhone 7 all the iPhones are coming with haptic engine. Prior to iPhone 7 Haptico will use standard vibration. Also Pattern play and impacts are not supported on devices prior to iPhone 7 and iOS 10

1. Generating predefined default feedbacks.

With Haptico you can generate three default types of haptic notifications:

public enum HapticoNotification {
    case success
    case warning
    case error
}

Here is small example how can you generate Success, Warning and Error feedbacks:

@IBAction func generateSuccess(_ sender: Any) {
    Haptico.shared().generate(.success)
}
@IBAction func generateWarning(_ sender: Any) {
    Haptico.shared().generate(.warning)
}
@IBAction func generateError(_ sender: Any) {
    Haptico.shared().generate(.error)
}

2. Generating impact feedbacks

Besides default haptic notifications, Haptico can also generate impact notifications. The library supports three types of impact notifications (available in iOS10+ and staring from iPhone 7):

public enum HapticoImpact {
    case light
    case medium
    case heavy
}

And to use them call:

Haptico.shared().generate(.medium)

Easy, huh?

3. Pattern play

And now something special - Pattern Play. Haptico can play patterns, "coded" as String. Let's take a look at small example:

Haptico.shared().generateFeedbackFromPattern("..oO-Oo..", delay: 0.1)

Each character in this string represents some specific haptic impact:

  • "O" (capital "o") - heavy impact
  • "o" - medium impact
  • "." - light impact
  • "-" - delay which has duration of 0.1 second

4. UI extensions

Haptico comes with a couple of UI Extensions: HapticoButton (which is subclass of UIButton) and UIAlertController extension with haptic feedback.

In order to start using HapticoButton - just set the class name in your Storyboard to HapticoButton. Then with UIControlEvents.touchDown event you will get heavy impact feedback and with UIControlEvents.touchUpInside and UIControlEvents.touchUpOutside you will get light impact feedback.

To use Haptico together with UIAlertController follow this simple example:

func showSuccessAlert() {
    let alert = UIAlertController(title: "Alert Title", message: "Alert Message", preferredStyle: .alert)
    alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
    present(alert, animated: true, hapticNotification: .success)
}

Installation

Haptico is available through CocoaPods, Carthage and Swift Package Manager.

Cocoapods

To install it using CocoaPods, simply add the following line to your Podfile:

pod 'Haptico'

Carthage

To install it via Carthage, add the following line to your Cartfile and follow the instructions to adding frameworks to an application:

github "iSapozhnik/Haptico"

Swift Package Manager

To install it using the Swift Package Manager, either directly add it to your project using Xcode 11, or specify it as dependency in the Package.swift file:

// ...
dependencies: [
    .package(url: "https://github.com/iSapozhnik/Haptico.git", from: "1.1.0"),
],
//...

Mentions

Author

isapozhnik, [email protected]

Donation

If you like this project and it helps you to reduce time to develop, you can give me a cup of β˜•οΈ πŸ˜‰

Donate

License

Haptico is available under the MIT license. See the LICENSE file for more info.

More Repositories

1

NavigationMenu

[DEPRECATED] Objective-C component that adds menu to the navigation bar
Objective-C
261
star
2

Popover

Custom macOS Popover πŸ’¬
Swift
124
star
3

Menu

The most customizable menu for macOS apps.
Swift
117
star
4

SegmentedProgressView

πŸ”˜πŸ”˜πŸ”˜βšͺ️βšͺ️ Simple Instagram-like segmented progress view with completion handler and different time interval for each segment
Swift
93
star
5

Snackbar

A Snackbar for macOS applications
Swift
13
star
6

SoundPlayer

πŸ”ŠSuper simple, low-latency sound player.
Swift
4
star
7

StatesController

UIViewController which implements switching states: Loading, No Data, Error and Content
Swift
4
star
8

LaRevenueCat

LaMetric dashboard for RevenueCat
Swift
3
star
9

Anchor

Swift
3
star
10

CopyIt

Showing Copy menu for each and every view in your app βœ‚οΈ
Swift
2
star
11

LoadingViewController

View controller which supports changing of it's content with predefined views: ContentView, LoadingView, ErrorView, NoDataView
Swift
2
star
12

ThumbnailsGenerator

Swift
2
star
13

Lasso

Intuitive and native Window Manager for Mac
2
star
14

InstagramStoryTransition

Swift
1
star
15

Widgy

1
star
16

CleanSwiftXCodeTemplates

Makefile
1
star
17

EventMonitor

Swift
1
star
18

AquaSmartGUI

C
1
star
19

Menu-Example

Example app for custom Mac OS Menu
Swift
1
star
20

SlidingButton

Swift
1
star
21

ViewPushBack

UIView push back
Objective-C
1
star
22

FamilyPocket-iOS

Simple app for family budget tracking πŸ’°
Swift
1
star
23

Altum

1
star
24

ShakeDetector

πŸŒ‹ A lightweight and customizable mouse shake detection library for macOS applications.
Swift
1
star
25

simctrl

Swift package which implements simctl functionality
Swift
1
star