Cinch turns a press-and-drag gesture into a 0–10 pain score. Four small pieces of code do the important work: how long you hold, which way you drag, what you feel, and how it teaches itself.
Outlined steps run on the UI thread as worklets, so the shape and the feel never wait on the rest of the app.
Holding still tightens the knot along a curve, not a straight line. The first levels arrive slowly, which gives fine control at the low end, where a 2 and a 3 should feel different.
export function levelFromHold(elapsedMs: number, base: number): number {
'worklet';
const t = elapsedMs - MOTION.deadzoneMs;
if (t <= 0) return clampLevel(base);
return clampLevel(base + MAX_LEVEL * Math.pow(t / MOTION.holdFullMs, MOTION.holdCurve));
}
export function levelFromDrag(dragBase: number, dy: number): number {
'worklet';
return clampLevel(dragBase + dy / MOTION.dragPxPerLevel);
}A single pan gesture handles everything. What happens depends on how long the finger stays down and how far it moves.
const gesture = usePanGesture({
minDistance: 0,
// finger lands: start the hold timer
onBegin: () => {
pressing.set(true);
pressStart.set(clock.get());
},
// finger moves more than 14px: switch from holding to dragging
onUpdate: (e) => {
if (!dragging.get() && Math.abs(e.translationY) > 14) dragging.set(true);
if (dragging.get()) level.set(levelFromDrag(dragBase.get(), -e.translationY));
},
// finger lifts: a quick tap is undone, anything else is saved
onFinalize: () => {
if (wasQuickTap()) return undoAndWobble();
level.set(Math.round(level.get()));
scheduleOnRN(onSet, level.get());
},
});Each moment has its own buzz, so people learn the gesture without reading. A tick fires only when the whole number changes during a press.
// one feel per moment
export const haptic = {
grab: () => impact(Soft), // finger lands
tick: (level) => impact(level >= 7 ? Heavy
: level >= 4 ? Medium : Light), // each level
wall: () => impact(Heavy).then(() => impact(Rigid)), // reached 10
set: () => impact(Rigid), // let go
tapError: () => notification(Warning), // tapped instead
};On first use, a fingertip demo loops over the knot: up for more pain, all the way down for less. It only moves on when the person does it themselves: up at least 3 levels, then down at least 2 while still holding, then let go. That way everyone feels the haptics build and soften at least once.
const onLevel = useCallback((level: number) => {
current.current = level;
peak.current = Math.max(peak.current, level);
setStep((s) => {
if (s === 'up' && level - start.current >= COACH.upLevels) return 'down';
if (s === 'down' && peak.current - level >= COACH.downLevels) return 'release';
return s;
});
}, []);