Documentation
¶
Overview ¶
Package haptics plays the phone's taps and buzzes: the system's own feedback (Impact, Notify, Selection) and patterns of your own (Play) — Core Haptics on iOS, the vibrator's effects on Android. Every call returns at once (the feedback plays on its own), so they are safe anywhere, handlers included. On phones without a haptic engine they do nothing.
On the web, call them through For(ctx), with the ctx a query, action or effect gives you: the browser vibrates where it can (Chrome on Android; not iPhones), and does nothing elsewhere.
haptics.Impact(haptics.Medium, 1) // a tap
haptics.Notify(haptics.Success) // something worked
haptics.Play([]haptics.Event{ // a thud, then a hum
{Intensity: 1, Sharpness: 0.35},
{At: 50 * time.Millisecond, Duration: time.Second, Intensity: 0.9, Sharpness: 0.3},
})
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Notify ¶
func Notify(kind Kind)
Notify is the system's feedback for a success, warning or error.
Types ¶
type Curve ¶
type Curve struct {
Sharpness bool // false: the curve is for intensity
Points []Point // its values over time
}
Curve changes a pattern's intensity or sharpness over time while it plays (a hum that swells). Intensity values multiply (0…1); sharpness values add (-1…1).
type Event ¶
type Event struct {
At, Duration time.Duration // when it starts, and how long it lasts; a Duration of 0 is a tap
Intensity, Sharpness float32 // each 0 to 1: how strong, and how crisp rather than round
}
Event is one moment of a pattern: a tap (Duration 0) or a buzz that lasts Duration, At its offset from the start. Intensity and Sharpness are 0…1: how strong, and how crisp rather than round.
type Feedback ¶ added in v0.0.14
type Feedback struct {
// contains filtered or unexported fields
}
Feedback plays haptics for a ctx's phone or browser tab.
func For ¶ added in v0.0.14
For is the same calls for ctx: the way to reach a browser tab on the web.
func (Feedback) Notify ¶ added in v0.0.14
Notify is the system's feedback for a success, warning or error.