{"id":15170621,"url":"https://github.com/liyanan2004/swiftui-haptics","last_synced_at":"2025-08-20T22:32:54.343Z","repository":{"id":65661100,"uuid":"585181313","full_name":"LiYanan2004/SwiftUI-Haptics","owner":"LiYanan2004","description":"A set of super-light modifiers and functions that adds haptic feedbacks to any SwiftUI View.","archived":false,"fork":false,"pushed_at":"2024-02-03T11:24:12.000Z","size":21,"stargazers_count":21,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-19T07:21:30.889Z","etag":null,"topics":["haptic-feedback","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/LiYanan2004.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":"2023-01-04T14:23:35.000Z","updated_at":"2024-12-07T20:06:30.000Z","dependencies_parsed_at":"2023-02-17T19:15:35.973Z","dependency_job_id":null,"html_url":"https://github.com/LiYanan2004/SwiftUI-Haptics","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiYanan2004%2FSwiftUI-Haptics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiYanan2004%2FSwiftUI-Haptics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiYanan2004%2FSwiftUI-Haptics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiYanan2004%2FSwiftUI-Haptics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LiYanan2004","download_url":"https://codeload.github.com/LiYanan2004/SwiftUI-Haptics/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230462967,"owners_count":18229870,"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":["haptic-feedback","swift","swiftui"],"created_at":"2024-09-27T08:04:17.270Z","updated_at":"2024-12-19T16:20:21.834Z","avatar_url":"https://github.com/LiYanan2004.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftUI-Haptics\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FLiYanan2004%2FSwiftUI-Haptics%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/LiYanan2004/SwiftUI-Haptics)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FLiYanan2004%2FSwiftUI-Haptics%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/LiYanan2004/SwiftUI-Haptics)\n\n`Haptics` has a set of super-light modifiers and functions that adds haptic feedbacks to any SwiftUI `View`, for example, when the specific property changes or equals to a specific value, the feedback will be triggered automatically.\n\n```swift\nimport SwiftUI\nimport Haptics\n⋮\n⋮\nYourView()\n    .hapticFeedback(.selection, trigger: isSelected)\n```\nor using the function programmatically\n```swift\nHapticGenerator.performFeedback(.selection)\n```\n\n## Platforms\n\n- iOS 14.0+\n- watchOS 7.0+\n- macOS 11.0+\n\n## Haptic Feedbacks\n\n - `start`: Indicates that an activity started. **(watchOS only)**\n - `stop`: Indicates that an activity stopped. **(watchOS only)**\n - `alignment`: Indicates the alignment of a dragged item. **(macOS only)**\n - `decrease`: Indicates that an important value decreased below a significant threshold. **(watchOS only)**\n - `increase`: Indicates that an important value increased above a significant threshold. **(watchOS only)**\n - `levelChange`: Indicates movement between discrete levels of pressure. **(macOS only)**\n - `selection`: Indicates that a UI element’s values are changing. **(iOS \u0026 watchOS)**\n - `success`: Indicates that a task or action has completed. **(iOS \u0026 watchOS)**\n - `warning`: Indicates that a task or action has produced a warning of some kind. **(iOS \u0026 watchOS)**\n - `error`: Indicates that an error has occurred. **(iOS \u0026 watchOS)**\n - `impact`: Provides a physical metaphor you can use to complement a visual experience. **(iOS \u0026 watchOS)**\n\n## Value-based Haptic Feedbacks\n\nPlay haptic feedbacks when the value changes.\n\n```swift\nYourView()\n    .hapicFeedback(.selection, trigger: isSelected)\n```\n \n## Dynamic Haptic Feedbacks\n\nIf the value being monitored changes, returns a `HapticFeedback` to be performed. \n\nReturn `nil` means **DO NOT** perform any haptics.\n\nYou can provide different haptic feedbacks based on your trigger value.\n\n```swift\nYourView()\n    .hapicFeedback(trigger: workStatus) { _, newValue in\n        return switch {\n        case .success: .success\n        case .failure: .error\n        default: nil\n        }\n    }\n    .hapicFeedback(.impact, trigger: cameraSession.capturedPhoto) { _, newValue in\n        return newValue == true // Only plays feedback when photo has been taken\n    }\n```\n\n## Looks familiar?\n\nYeah. \n\nIf you want to use `.sensoryFeedback` API but need to support older platform, `SwiftUI-Haptics` is a better solution.\n\nReplace `sensoryFeedback` to `hapticFeedback`. \n\nEverything just works.\n\n## Swift Package Manager\n\nIn your `Package.swift` Swift Package Manager manifest, add the following dependency to your `dependencies` argument:\n\n```swift\n.package(url: \"https://github.com/LiYanan2004/SwiftUI-Haptics.git\", .branch(\"main\")),\n```\n\nAdd the dependency to any targets you've declared in your manifest:\n\n```swift\n.target(name: \"MyTarget\", dependencies: [\"Haptics\"]),\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliyanan2004%2Fswiftui-haptics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliyanan2004%2Fswiftui-haptics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliyanan2004%2Fswiftui-haptics/lists"}