haptics

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 3 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 the web, and on phones without a haptic engine, they do nothing.

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 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