← Back to the Cinch case study
Cinch · under the hood

How Cinch works

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.

React Native + ExpoReanimated 4Gesture Handler 3SkiaExpo Haptics
Finger down→ Gesture→ Level 0–10→ Petals + haptics→ Let go→ Score + advice

Outlined steps run on the UI thread as worklets, so the shape and the feel never wait on the rest of the app.

Holding

A slow start, so low levels are easy to land

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.

  • 150 ms dead zone so a brush of the finger does nothing.
  • level = 10 × t1.35, reaching 10 after 4.5 s.
  • Dragging moves 1 level every 26 px, in either direction.
0 5 10 0s 1s 2s 3s 4.65s Level 3 · 2.0s Level 7 · 3.6s
Level over hold time. Shaded: the dead zone.
src/pain-squeeze/mapping.ts
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);
}
The gesture

One press, three possible outcomes

A single pan gesture handles everything. What happens depends on how long the finger stays down and how far it moves.

  • Hold still: the level builds over time from where it was.
  • Move more than 14 px: switch to adjusting. Up tightens, down eases off.
  • Let go within 250 ms without moving: treat it as a tap. Undo, wobble, and show "Keep your finger on it".
Simplified from usePainSqueeze.ts
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());
  },
});
Haptics

A vocabulary you learn by feel

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.

  • Grab: soft, the instant the finger lands.
  • Tick: light, then medium, then heavy as the level rises.
  • Wall: a double bump at 10.
  • Set: a crisp click on release.
  • Tap error: a warning buzz when someone taps instead of pressing.
Simplified from haptics.ts
// 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
};
Teaching it once

A walkthrough you have to do, not watch

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.

src/pain-squeeze/useCoach.ts
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;
  });
}, []);