{"id":17269573,"url":"https://github.com/kanecheshire/hapticgenerator","last_synced_at":"2025-04-14T08:41:19.865Z","repository":{"id":56914423,"uuid":"89360409","full_name":"KaneCheshire/HapticGenerator","owner":"KaneCheshire","description":"Easy peasy haptic generation in iOS.","archived":false,"fork":false,"pushed_at":"2020-06-16T13:57:18.000Z","size":91,"stargazers_count":35,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-13T02:35:35.652Z","etag":null,"topics":["haptics","ios","ipad","iphone","uifeedbackgenerator"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KaneCheshire.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-25T12:54:38.000Z","updated_at":"2024-03-20T07:25:30.000Z","dependencies_parsed_at":"2022-08-20T20:50:36.935Z","dependency_job_id":null,"html_url":"https://github.com/KaneCheshire/HapticGenerator","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KaneCheshire%2FHapticGenerator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KaneCheshire%2FHapticGenerator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KaneCheshire%2FHapticGenerator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KaneCheshire%2FHapticGenerator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KaneCheshire","download_url":"https://codeload.github.com/KaneCheshire/HapticGenerator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248848808,"owners_count":21171451,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["haptics","ios","ipad","iphone","uifeedbackgenerator"],"created_at":"2024-10-15T08:16:47.710Z","updated_at":"2025-04-14T08:41:19.845Z","avatar_url":"https://github.com/KaneCheshire.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HapticGenerator\nEasy peasy haptic generation in iOS.\n\n[![CI Status](http://img.shields.io/travis/KaneCheshire/HapticGenerator.svg?style=flat)](https://travis-ci.org/kanecheshire/HapticGenerator)\n[![Version](https://img.shields.io/cocoapods/v/HapticGenerator.svg?style=flat)](http://cocoapods.org/pods/HapticGenerator)\n[![License](https://img.shields.io/cocoapods/l/HapticGenerator.svg?style=flat)](http://cocoapods.org/pods/HapticGenerator)\n[![Platform](https://img.shields.io/cocoapods/p/HapticGenerator.svg?style=flat)](http://cocoapods.org/pods/HapticGenerator)\n\n## Installation\n\n### Swift Package Manager\n\nHapticGenerator supports SPM, simply add HapticGenerator as a package dependency in Xcode 11 or newer.\n\n### Cocoapods\n\nAdd the following to your podfile:\n\n```ruby\npod 'HapticGenerator'\n```\n\nand then run `pod update` in Terminal.\n\n### Manual\n\nOr you can just add `HapticGenerator.swift` to your project manually.\n\n## Migrating from HapticGenerator 2 to HapticGenerator 3\n\n**HapticGenerator 3.0.0 significantly simplifies naming, but will be a breaking change requiring you to update your app.**\n\nIn **HapticGenerator 3**, the line of code to generate a haptic has been simplified:\n\n```swift\nHaptic.selection.generate()\nHaptic.selection.generate(prepareForReuse: true)\n```\n\nCompared to **HapticGenerator 2** which was a bit too verbose for no real good reason:\n\n```swift\nHapticGenerator.selection.generateHaptic()\nHapticGenerator.selection.generateHaptic(prepareForReuse: true)\n```\n\n## Usage\n\n**HapticGenerator** now comes with convenience constants so generating haptics is even easier:\n\n```swift\nHaptic.selection.generate()\n```\n\nAlternatively, if you'd rather create the generators yourself simply create a new generator like so:\n\n```swift\nlet selection = Haptic(.selection)\nlet lightImpact = Haptic(.impact(.light))\nlet warning = Haptic(.notification(.warning))\n```\n\nAnd then generate a haptic like so:\n\n```swift\nselection.generate()\n```\n\nOptionally, you can tell the system to prepare the engine for (re)use.\n**HapticGenerator** has two ways to do this, either after you generate a haptic by setting `prepareForReuse` to `true`:\n\n```swift\nHaptic.selection.generate(prepareForReuse: true)\n```\n\nOr if you know in advance before generating a haptic that you'll need to use it soon (after a screen appears for example),\nthen you can `prepareForUse` manually:\n\n```swift\nHaptic.selection.prepareForUse()\n```\n\n\u003e **Note:** Haptics should only be generated and prepared for reuse on the main thread.\n\n## Why use this?\n\nApple's `UIFeedbackGenerator` subclasses are not difficult to use, but they _are_ messy.\n\n**HapticGenerator** tidies this up and makes the process of creating different types of haptics on iOS easy and coherent.\n\nSee the difference between creating and using generators of different types Apple's way, and the **HapticGenerator** way:\n\n```swift\n\n// Apple's way of using a selection feedback generator:\nlet selection = UISelectionFeedbackGenerator()\n// Generate the haptic:\nselection.selectionChanged()\n\n// Apple's way of using an impact feedback generator:\nlet lightImpact = UIImpactFeedbackGenerator(style: .light)\nlightImpact.impactOccurred()\n\n// Apple's way of using a notification feedback generator:\nlet success = UINotificationFeedbackGenerator()\nsuccess.notificationOccurred(.success)\n```\n\nCompared to the **HapticGenerator** way:\n\n```swift\nHaptic.selection.generate()\n\nHaptic.lightImpact.generate()\n\nHaptic.success.generate()\n```\n\n**HapticGenerator** is significantly less code to write and easier to follow.\n\nFurthermore, if you support any iOS version prior to iOS 10, you won't have ugly availability checks throughout your code because it is all contained within **HapticGenerator**.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanecheshire%2Fhapticgenerator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkanecheshire%2Fhapticgenerator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanecheshire%2Fhapticgenerator/lists"}