Touch playback
A scripted finger for phone and tablet screens that glides, taps with a ring, holds and swipes. The touch twin of the agent cursor: the same props, so one script drives either.
On this page
Installation
Usage
import { PlainScreen } from "@/components/ui/chatcn/plain-screen"
import { TouchPlayback } from "@/components/ui/chatcn/touch-playback"
import { useFrameScript } from "@/lib/chatcn-frames"
const steps = [
{ wait: 700, set: { x: 0.46, y: 0.25, action: { id: "a", kind: "tap", label: "Tap Priya Raman" } } },
{ wait: 1200, set: { x: 0.04, y: 0.5, action: null } },
{ wait: 600, set: { x: 0.8, y: 0.5, action: { id: "b", kind: "swipe", label: "Swipe back" } } },
] as const
function Demo() {
const { state, ref } = useFrameScript(steps, { x: 0.5, y: 0.6, action: null }, { loop: true })
return (
<PlainScreen ref={ref} width={300}>
<div dir="ltr" className="relative size-full">
<MyApp />
<TouchPlayback x={state.x} y={state.y} action={state.action} />
</div>
</PlainScreen>
)
}Place it inside the positioned box that holds the screen. x and y run from 0 to 1 across that box, so the finger lands on the same spot at any rendered size. Between touches it glides on the agent cursor's curve and timing; after idleAfter ms without a gesture it lifts away, and the next touch comes down where it happens instead of travelling there.
tap(orclick,select): the dot presses to 85% in 80 ms, one ring grows from 28 to 56 px as it fades, and the dot releases in 140 ms.long-press: the ring grows and holds forholdms (default 500), then fades as the finger lifts.swipe(ordrag,scroll): the finger presses where it is and travels tox,yheld down in a straight stroke, with a 120 ms tail that narrows and fades behind it.- Other kinds (
type,hover,wait) only move the finger, so a script written for the agent cursor plays as it is.
Content that should follow a swipe, like a page sliding back, can use the stroke's timing: 240 + distance * 0.55 ms, at most 720, on cubic-bezier(0.45, 0, 0.15, 1). Each new action is announced politely ("Agent: Swipe back"); pass announce={false} when the screen announces its own changes. Under reduced motion the finger jumps and each gesture shows a 120 ms ring. Screens are pictures, so the finger does not mirror in RTL: keep the screen it plays over in dir="ltr" so its script lands on the same spots in every page direction.
Examples
States
A tap that flips a toggle, a long press whose ring holds before the menu, a swipe that archives a row, and the same finger on a tablet.
Props
| Prop | Type | Notes |
|---|---|---|
x, y | number | 0 to 1 of the screen |
action | { id?, kind, label, hold? } | A new id plays the gesture again |
state | active | idle | hidden | Idle dims the finger; hidden lifts it |
name | string | For the announcement. Default "Agent" |
speed | number | Glide speed multiplier. Default 1 |
idleAfter | number | ms before the finger lifts. Default 900 |
announce | boolean | Default true |
onArrive | () => void | When the finger lands |