haptics

package
v0.0.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 4 Imported by: 0

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 Impact

func Impact(style Style, intensity float32)

Impact is a single tap of a style, at intensity (0…1).

func Notify

func Notify(kind Kind)

Notify is the system's feedback for a success, warning or error.

func Play

func Play(events []Event, curves ...Curve)

Play plays a pattern. Android plays its taps and buzzes with their strength; it can't vary sharpness, and its curves are sampled.

func Selection

func Selection()

Selection is the light tick of a choice changing.

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

func For(ctx context.Context) Feedback

For is the same calls for ctx: the way to reach a browser tab on the web.

func (Feedback) Impact added in v0.0.14

func (f Feedback) Impact(style Style, intensity float32)

Impact is a single tap of a style, at intensity (0…1).

func (Feedback) Notify added in v0.0.14

func (f Feedback) Notify(kind Kind)

Notify is the system's feedback for a success, warning or error.

func (Feedback) Play added in v0.0.14

func (f Feedback) Play(events []Event, curves ...Curve)

Play plays a pattern.

func (Feedback) Selection added in v0.0.14

func (f Feedback) Selection()

Selection is the light tick of a choice changing.

type Kind

type Kind string

Kind is what a Notify says.

const (
	Success Kind = "success"
	Warning Kind = "warning"
	Error   Kind = "error"
)

type Point

type Point struct {
	At    time.Duration // when, from the start
	Value float32       // the value then
}

Point is a Curve's value At a moment.

type Style

type Style string

Style is how an Impact feels.

const (
	Light  Style = "light"
	Medium Style = "medium"
	Heavy  Style = "heavy"
	Soft   Style = "soft"
	Rigid  Style = "rigid"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL