Usage
Experimental: this hook may change or be removed in a patch release. Tracks presses on a control with UIControl's rules: the highlight comes on in the same frame (or after the content-touch delay inside a scroller), the finger stays inside up to 70 pt beyond the bounds, dragging out and back in turns the highlight off and on, and a recognizer or the browser taking the touch cancels the press with no release. Activation stays the browser's click; the press tracker only drives the highlight and the control events. PRESS_PROFILES.control and PRESS_PROFILES.cell carry UIKit's two profiles (a button's and a list cell's) as options to spread.
tsimport {usePressTracker} from '@astryxdesign/core'
Best practices
| Guidance | Practices |
|---|---|
| Do | Keep activation on the click (or onPress of an Astryx control); use touchUpInside only for feedback such as a haptic. |
| Do | Spread |
| Don't | Track presses with pointerdown/pointerup and a boolean state; it un-presses the moment the finger slides off and lights up during flicks. |
Parameters
| Param | Type | Description |
|---|---|---|
refrequired | RefObject<Element | null> | The control whose presses are tracked. |
options.onHighlightChange | (isHighlighted: boolean) => void | Called when the pressed highlight should come on or go off. Paint it here (for example by setting an attribute your styles read). |
options.onControlEvent | (event: , touch: ) => void | UIControl's events: touchDown, touchDragInside, touchDragOutside, touchDragEnter, touchDragExit, touchUpInside, touchUpOutside and touchCancel. |
options.highlightDelay | 'inScrollers' | 'always' | 'never' (default: 'inScrollers') | When the highlight waits UIScrollView's content-touch delay (about 150 ms) so a flick paints nothing: inside a scroller (a control), always (a list cell), or never. |
options.cancelTravel | number | Travel in px past which the press is cancelled for good, as a cell is when its scroll view takes the touch. Unset, the finger is tracked in and out of the expanded bounds. |
options.quickTapFlash | number (default: 100) | How long a tap quicker than the delay shows the highlight at the lift, in ms; 0 goes straight into the release. |
options.trackingExpansion | number (default: 70) | How far outside the bounds the finger still counts as inside, in px (UIControl uses 70 pt). |
options.vetoesAncestorRecognizer | (recognizer: GestureRecognizer) => boolean | Which ancestor recognizers the control's own action beats. By default, an ancestor's single-finger single tap (UIKit's rule for controls); a slider would also veto a pan along its track. |
options.isEnabled | () => boolean | Read at touch-down; a disabled control tracks nothing. |
Returns
| Field | Type | Description |
|---|---|---|
| tracker | PressTracker | The tracker, stable across renders. |
Use with shadcn
Already using the shadcn registry workflow? Install the real Astryx package and a local public re-export. Component implementation source stays in Astryx.
This install URL expires with the draft preview.bashnpx shadcn@4.19.0 add https://astryx-n0r7vdkp1-fbopensource.vercel.app/shadcn/hooks/use-press-tracker.json