{"id":28754622,"url":"https://github.com/dm-zharov/haptic-feedback","last_synced_at":"2025-06-17T01:10:38.068Z","repository":{"id":230895319,"uuid":"780368538","full_name":"dm-zharov/haptic-feedback","owner":"dm-zharov","description":"Backport of SensoryFeedback API. Supports iOS 14, macOS 11, watchOS 7","archived":false,"fork":false,"pushed_at":"2025-01-17T13:45:02.000Z","size":21,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-16T11:03:30.388Z","etag":null,"topics":["backport","feedback","haptic","sensory","swift","swiftui"],"latest_commit_sha":null,"homepage":"","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/dm-zharov.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-04-01T10:26:45.000Z","updated_at":"2025-05-15T20:42:39.000Z","dependencies_parsed_at":"2024-04-01T13:02:54.315Z","dependency_job_id":null,"html_url":"https://github.com/dm-zharov/haptic-feedback","commit_stats":null,"previous_names":["dm-zharov/swift-haptic-feedback","dm-zharov/sensory-feedback-backport"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/dm-zharov/haptic-feedback","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dm-zharov%2Fhaptic-feedback","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dm-zharov%2Fhaptic-feedback/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dm-zharov%2Fhaptic-feedback/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dm-zharov%2Fhaptic-feedback/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dm-zharov","download_url":"https://codeload.github.com/dm-zharov/haptic-feedback/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dm-zharov%2Fhaptic-feedback/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260269458,"owners_count":22983648,"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":["backport","feedback","haptic","sensory","swift","swiftui"],"created_at":"2025-06-17T01:10:34.538Z","updated_at":"2025-06-17T01:10:38.056Z","avatar_url":"https://github.com/dm-zharov.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HapticFeedback\n\n[![Platforms](https://img.shields.io/badge/platforms-_iOS_|_macOS_|_watchOS-lightgrey.svg?style=flat)](https://developer.apple.com/resources/)\n[![SPM supported](https://img.shields.io/badge/SPM-supported-DE5C43.svg?style=flat)](https://swift.org/package-manager)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](http://mit-license.org)\n\n## Features\n\nBackport of SwiftUI Sensory Feedback API (iOS 17).\n\n```swift\n// Native API. Only works on iOS 17, macOS 14, watchOS 10\n.sensoryFeedback(.selection, trigger: value)\n\n// Backport. Compatible with iOS 14, macOS 11, watchOS 7\n.hapticFeedback(.selection, trigger: value)\n```\n\nDirectly play Haptic Feedback.\n\n```swift\n// Determines if device supports haptic feedback\nHapticFeedback.isAvailable\n\n// Plays selection feedback\nHapticFeedback.selection.play()\n\n// Plays impact feedback\nHapticFeedback.impact(weight: .heavy, intensity: 0.5).play()\n```\n\n## Installation\n\nThe implementation is encapsulated in a single file, so you can simply drag the `HapticFeedback.swift` file into your project to use it.\n\n#### Requirements\n\n* iOS 14.0+, macCatalyst 14.0+, macOS 11.0+, watchOS 7.0+\n* Swift 5.9\n\n#### Swift Package Manager\n\nTo use the `HapticFeedback`, add the following dependency in your `Package.swift`:\n```swift\n.package(url: \"https://github.com/dm-zharov/haptic-feedback.git\", from: \"1.0.0\")\n```\n\nFinally, add `import HapticFeedback` to your source code.\n\n## Usage\n\n#### Trigger On Value Changes\n\nThe haptic feedback plays when the trigger values changes.\n\n```swift\nstruct MyView: View {\n    @State private var showAccessory = false\n\n    var body: some View {\n        Button(\"Backport\") {\n            showAccessory.toggle()\n        }\n        .hapticFeedback(.selection, trigger: showAccessory)\n    }\n}\n```\n\n#### Trigger With Condition Closure\n\nFor more control over when you trigger the feedback use the condition closure version of the view modifier.\n\n```swift\n.hapticFeedback(.selection, trigger: showAccessory) { oldValue, newValue in\n    return newValue == true\n}\n```\n\n#### Trigger With Feedback Closure\n\nFor control over what feedback plays use the feedback closure version of the view modifier.\n\n```swift\n.hapticFeedback(trigger: isFinished) { oldValue, newValue in\n    return newValue ? .success : .error\n}\n```\n\n## Communication\n\n- If you **found a bug**, open an issue.\n- If you **have a feature request**, open an issue.\n- If you **want to contribute**, submit a pull request.\n\n## Knowledge\n\n* [SwiftUI Sensory Feedback](https://useyourloaf.com/blog/swiftui-sensory-feedback/)\n* [NSHapticFeedbackPerformer](https://developer.apple.com/documentation/appkit/nshapticfeedbackperformer)\n* [UIFeedbackGenerator](https://developer.apple.com/documentation/uikit/uifeedbackgenerator)\n* [WKInterfaceDevice.play(_:)](https://developer.apple.com/documentation/watchkit/wkinterfacedevice/1628128-play)\n\n## Author\n\nDmitriy Zharov, contact@zharov.dev\n\n## License\n\nHapticFeedback is available under the MIT license. See the [LICENSE file](https://github.com/dm-zharov/haptic-feedback/blob/master/LICENSE) for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdm-zharov%2Fhaptic-feedback","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdm-zharov%2Fhaptic-feedback","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdm-zharov%2Fhaptic-feedback/lists"}