Ada LindqvistDesign Engineer

Building a Sheet

A bottom sheet looks simple. It is a panel that slides up from the bottom of the screen, and you can drag it back down to close it. I assumed it would take an afternoon. It took most of a month, and almost all of that time went into the drag.

Follow the finger, exactly

The first version moved the sheet with a CSS transition every time the pointer moved. It felt like dragging something through syrup, because every update started a new 200ms animation that was always behind your finger.

During a drag there should be no animation at all. The sheet's position is the pointer's position, set directly on every move:

function onPointerMove(event) {
  const delta = Math.max(0, event.clientY - startY);
  sheet.style.transform = `translateY(${delta}px)`;
}

The transition only comes back when you let go.

Velocity, not distance

My next mistake was deciding whether to close the sheet based on how far it was dragged. If you dragged past half its height, it closed. If not, it snapped back.

That is not how people use a sheet. A quick flick down should close it even if it only moved 40 pixels. So the release logic looks at speed first:

const velocity = distance / (Date.now() - startTime);
if (velocity > 0.11 || distance > sheetHeight * 0.5) close();
else snapBack();

The threshold came from trying values on a real phone until a lazy flick felt right. On a laptop trackpad you would pick something different, which is another reason to test on the device people will use.

Dragging up should resist

Pulling the sheet upward past its open position shouldn't do nothing, because that feels broken. It shouldn't move freely either. The answer is friction: the further you pull, the less it follows.

const resisted = 8 * (Math.log(Math.abs(delta) + 1) - 2);

It is a small thing, but it is the difference between a component that feels physical and one that feels like a div with a transform.

Scrolling inside the sheet

The hardest part was content that scrolls. If the sheet holds a long list, a downward drag should scroll the list until it reaches the top, and only then start moving the sheet. Getting that handoff right, without a jump in the middle of one continuous gesture, took more code than everything above combined.

What I would tell myself

Build the drag first, on a phone, before anything else. The opening animation, the backdrop and the styling are the easy parts. If the drag feels wrong, nothing else will save it.