Giter Site home page Giter Site logo

efremidze / haptica Goto Github PK

View Code? Open in Web Editor NEW
754.0 11.0 42.0 720 KB

Easy Haptic Feedback Generator ๐Ÿ“ณ

License: MIT License

Swift 89.14% Ruby 6.93% Objective-C 3.93%
haptic taptic ios swift ios10 vibrate feedback uibutton carthage cocoapods

haptica's Introduction

Haptica

Build Status Carthage Compatible Language Version License Platform

Haptica is an easy haptic feedback generator.

$ pod try Haptica

Requirements

  • iOS 9.0+
  • Xcode 8.0+
  • Swift 5 (Haptica 3.x), Swift 4 (Haptica 2.x), Swift 3 (Haptica 1.x)

Haptic Feedback Requirements:

  • A device with a supported Taptic Engine.
  • App is running in the foreground.
  • System Haptics setting is enabled.

Usage

Generate using a haptic feedback type.

Haptic.impact(.light).generate()

Feedback Types

  • Impact: (UIImpactFeedbackStyle) - Use impact feedback generators to indicate that an impact has occurred. For example, you might trigger impact feedback when a user interface object collides with something or snaps into place.
    • light
    • medium
    • heavy
  • Notification: (UINotificationFeedbackType) - Use notification feedback to communicate that a task or action has succeeded, failed, or produced a warning of some kind.
    • success
    • warning
    • error
  • Selection - Use selection feedback to communicate movement through a series of discrete values.

Vibration Patterns

Play a custom vibration pattern:

Haptic.play("..oO-Oo..", delay: 0.1)

Use pattern symbols to represent custom vibrations.

  • O - heavy impact
  • o - medium impact
  • . - light impact
  • X - rigid impact
  • x - soft impact
  • - - wait 0.1 second

Or play a symphony of notes:

Haptic.play([.haptic(.impact(.light)), .haptic(.impact(.heavy)), .wait(0.1), .haptic(.impact(.heavy)), .haptic(.impact(.light))])

UIButton Extension

To enable haptic feedback on buttons, set these properties:

  • isHaptic - enables haptic feedback
  • hapticType - haptic feedback type
button.isHaptic = true
button.hapticType = .impact(.light)

or use these functions to set the haptic feedback type for control events:

  • addHaptic() - add haptic feedback for control events
  • removeHaptic() - remove haptic feedback for control events
button.addHaptic(.selection, forControlEvents: .touchDown)
button.removeHaptic(forControlEvents: .touchDown)

Functions/Properties

var isHaptic: Bool // enables haptic feedback
var hapticType: Haptic? // haptic feedback type
var hapticControlEvents: UIControl.Event? // haptic feedback control events
func addHaptic(_ haptic: Haptic, forControlEvents events: UIControl.Event) {} // add haptic feedback for control events
func removeHaptic(forControlEvents events: UIControl.Event) {} // remove haptic feedback for control events

Sound Effects

Add sound effects to Haptica using Peep.

Peep.play(sound: KeyPress.tap)

Installation

CocoaPods

To install with CocoaPods, simply add this in your Podfile:

use_frameworks!
pod "Haptica"

Carthage

To install with Carthage, simply add this in your Cartfile:

github "efremidze/Haptica"

Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Mentions

License

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

haptica's People

Contributors

av0c0der avatar efremidze avatar kirillivonin avatar kirow avatar tsomaev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

haptica's Issues

How to stop while playing a note

How to stop while playing a long pattern

Haptic.play("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO", delay: 0.1)

I want to stop this when this is playing. Please show me a way to do it.

thanks

Is there a custom string limit?

Just wondering is there a max length on the custom string haptic? If so is it a sytem thing or is it limited by the pod itself?

No feedback until restart

Sometimes feedback stops working until I restart the device. Any idea as to why this issue may be happening?

Random crashes, exception UIFeedbackHapticOnlyEngine _deactivate

I am using Haptica in my app I recently release a new version of my app on 16 July after that repeating crashes are reported on Xcode organiser. Below are the exception details:-

ERROR: -[_UIFeedbackHapticOnlyEngine _deactivate] called more times than the feedback engine was activated

Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x1f7bc927c __exceptionPreprocess
1 libobjc.A.dylib 0x1f6da39f8 objc_exception_throw
2 CoreFoundation 0x1f7ae2988 +[_CFXNotificationTokenRegistration keyCallbacks]
3 Foundation 0x1f85a6188 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
4 UIKitCore 0x224055628 -[_UIFeedbackEngine _deactivate]
5 UIKitCore 0x22403e58c -[UIFeedbackGenerator __deactivateWithStyle:]
6 libdispatch.dylib 0x1f7608a38 _dispatch_call_block_and_release
7 libdispatch.dylib 0x1f76097d4 _dispatch_client_callout
8 libdispatch.dylib 0x1f75b7004 _dispatch_main_queue_callback_4CF$VARIANT$mp
9 CoreFoundation 0x1f7b5ac1c CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE
10 CoreFoundation 0x1f7b55b54 __CFRunLoopRun
11 CoreFoundation 0x1f7b550b0 CFRunLoopRunSpecific
12 GraphicsServices 0x1f9d5579c GSEventRunModal
13 UIKitCore 0x2244cf978 UIApplicationMain
14 Qpay 0x102253268 main + 16 (GeneratePasscodeInteractor.swift:16)
15 libdyld.dylib 0x1f761a8e0 start

Haptica version:- 3.0.0
Thanks

Feature Request: IBInspectable

There is only few options to configure a haptic button, it would be great if we can do it directly in StoryBoard inspector.

Usage in table view?

Thanks for this great library!

I'm trying to use it in a table view, and I have the following code:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  Haptic.impact(.medium).generate()
  // Other stuff...
}

This generates haptic feedback, but sometimes it seems to be generating two very fast consecutive ones. It happens when you click on one cell and then another.

Is it the wrong way to use the library? Thank you!

Fireworks sequence

Has anyone figured out the fireworks sequence and/or is there a collection of sequences out there to reuse?

How do you do a double tap?

I tried with the following pattern but nothing simulates a double tap, how do I do that?

addButton(pattern: "O")
addButton(pattern: "o")
addButton(pattern: ".")
addButton(pattern: ".-.")
addButton(pattern: "o-o")
addButton(pattern: "O-O")
addButton(pattern: "..oO-Oo..")
addButton(pattern: "O--O")
addButton(pattern: "o--o")
addButton(pattern: "o---o")
addButton(pattern: "O---O")
addButton(pattern: "o--O--O--o")
addButton(pattern: "o--O---O--o")
addButton(pattern: "O--O---O--O")
addButton(pattern: "OOO------------------------OOO")

Public API improvements

There is no real issue and this topic is more of an observation type.

Q.1:
I used Haptica as:

button.isHaptic = true // required call.
button.hapticType = .impact(.light) // optional, but has to be set.
button.hapticControlEvents = .touchUpInside // optional, default is .touchDown as per implementation.

My initialization logic has a flaw since button.isHaptic = true immediately triggers a call to addTarget() with .touchDown as default value (if hapticControlEvents is not set).
Hence hapticControlEvents should be initialized before button.isHaptic = true invocation to make any effect.

Would this make sense to refactor and introduce methods like these:

func addHaptic(_ haptic: Haptic, forControlEvents events: UIControl.Event = .touchUpInside)
func removeHaptic()

to enable 1 line setup?
Methods naming strategy 'addHaptic', 'removeHaptic' stolen from 'addTarget', 'removeTarget'.

Q.2:
Does it make sense to implement Hapticable for UIControl rather than UIButton? (since addTarget and removeTargets methods implemented in UIControl).
This would enable Haptics for elements like UISwitch.

Use Latest Haptic Feedback API

Overview

As the technology for haptic feedback evolves, new syntax and methods are introduced to improve performance and expand capabilities. It has come to my attention that this repository's implementation of haptic feedback may be outdated. Updating to the latest syntax can enhance the user experience, provide more precise control over feedback, and ensure compatibility with the newest devices.

Suggested Changes

I recommend updating the haptic feedback implementation to utilize the latest syntax introduced in [specific version or framework name, if applicable]. This update can bring several improvements:

  • Enhanced Performance: New methods are optimized for faster response times and smoother feedback transitions.
  • Extended Functionality: The latest syntax supports a wider range of feedback patterns and intensities, allowing for more nuanced user interactions.
  • Future-proofing: Ensuring compatibility with the latest and upcoming devices that users may adopt.

Examples

Here are a few examples of the changes in syntax from the current implementation to the proposed one:

  • Old Syntax: [Provide example of the current syntax]
  • New Syntax: [Provide example of the new syntax]

These examples illustrate how the new syntax can provide clearer, more concise code and better control over haptic feedback.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.