Update README
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.
Haptics
View
import SwiftUI import Haptics ⋮ ⋮ YourView() .haptics(onChangeOf: value, type: .soft)
or using the function programmatically
@Environment(\.hapticGenerator) var generator ⋮ generator.hapticFeedbackOccurred(type: .click)
Sometimes, you just want to play haptic feedbacks only at a specific state. At this time, .haptics(when:equalsTo:type:) plays a role.
.haptics(when:equalsTo:type:)
Of course, you can create multiple haptics on a single view:
YourView() .haptics(when: value, equalsTo: .success, type: .success) .haptics(when: value, equalsTo: .failure, type: .error)
You can play a one-time haptic feedback when a view appears.
Text("I love haptics.") .triggersHapticFeedbackWhenAppear()
In your Package.swift Swift Package Manager manifest, add the following dependency to your dependencies argument:
Package.swift
dependencies
.package(url: "https://github.com/LiYanan2004/SwiftUI-Haptics.git", .branch("main")),
Add the dependency to any targets you’ve declared in your manifest:
.target(name: "MyTarget", dependencies: ["Haptics"]),
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
SwiftUI-Haptics
Haptics
has a set of super-light modifiers and functions that adds haptic feedbacks to any SwiftUIView
, for example, when the specific property changes or equals to a specific value, the feedback will be triggered automatically.or using the function programmatically
Feedback Types
Platforms
Conditional Haptics
Sometimes, you just want to play haptic feedbacks only at a specific state. At this time,
.haptics(when:equalsTo:type:)
plays a role.Of course, you can create multiple haptics on a single view:
onAppear Haptics
You can play a one-time haptic feedback when a view appears.
Swift Package Manager
In your
Package.swift
Swift Package Manager manifest, add the following dependency to yourdependencies
argument:Add the dependency to any targets you’ve declared in your manifest: