Skip to content
Crafts

A drawer that follows your thumb

Craft 03 · React Native, motion

Dragged, flicked and carried, all in one transform.

Every drawer in Baseband is the same component, tuned until it felt like part of the phone. This is the one that asks for your router's address.

Baseband address drawer: waiting for an address
01 waiting for an address
Baseband address drawer: checking
02 checking
Baseband address drawer: nothing answered
03 nothing answered
Baseband address drawer: rides the keyboard
04 rides the keyboard
Fig. 1The address drawer in Baseband, on an iPhone: waiting, checking, nothing answered, and riding the keyboard.

Baseband talks to your router directly, and when it can't find it, it asks for the router's address. That one question lives in a drawer, and the drawer has to survive a keyboard opening under it, a phone with a home indicator, a tab bar, a flick, and someone who prefers no motion at all. It's Baseband's own Sheet component, built on Reanimated, Gesture Handler and react-native-keyboard-controller, and everything that moves runs on the UI thread.

The drawer's position is a single translateY, and everything that moves it adds into that one number: the drag offset while your thumb is on it, the spring when it opens, and the keyboard. keyboard-controller exposes the keyboard's height as a shared value that changes on every frame of the keyboard's own animation, so folding it into the same transform means the drawer and the keys travel together. Drag the drawer while the keyboard is up and both still agree, because there's only one position to agree on.

components/ui/Sheet.tsx · tsx
const sheetStyle = useAnimatedStyle(() => ({
  opacity: opacity.get(),
  transform: [
    {
      translateY:
        Math.max(offset.get(), 0) +
        Math.min(0, keyboard.height.get() + WINDOW_BOTTOM),
    },
  ],
}));

The drawer measures its content and travels exactly that far, instead of a hardcoded 400 pixels. When something inside grows, like the error line appearing, the offset absorbs the difference and springs back, so the drawer grows upward instead of jumping. It also never shrinks: its minimum height ratchets up to the tallest it has been, and the note under the field always reserves two lines. Going from checking to failed to typing again, the button never moves under your thumb.

components/ui/Sheet.tsx · tsx
const onLayout = (e: LayoutChangeEvent) => {
  const measured = e.nativeEvent.layout.height;
  const previous = height.get();
  height.set(measured);
  if (measured > floor) setFloor(measured);
  if (!visible || leaving.get()) return;
  if (previous === 0) {
    offset.set(measured);
    show();
  } else if (measured > previous) {
    offset.set(offset.get() + measured - previous);
    show();
  }
};

Dragging follows the finger one to one. Letting go doesn't just compare where it stopped: it projects where it was headed, a tenth of a second of velocity ahead, and closes if that lands past half the drawer's height. A short slow drag springs back; a quick flick from anywhere closes it.

components/ui/Sheet.tsx · tsx
.onEnd((e) => {
  if (offset.get() + e.velocityY * FLICK_PROJECTION > height.get() / 2) {
    hide(e.velocityY);
    scheduleOnRN(onDismiss);
  } else {
    offset.set(
      withSpring(0, { ...Motion.spring.gentle, velocity: e.velocityY }),
    );
  }
});

While the address is being checked, Cancel is disabled, so the backdrop, the drag and Android's back button refuse too; nothing gets a way out that the visible button doesn't. Each check gets a number, and an answer that comes back for an older one is ignored. The button itself is the same pill the whole time: grey until the text is a valid address, a spinner while it checks, then Try again. The error says what happened, with the address and how long it waited. VoiceOver's escape gesture closes the drawer, and under reduced motion it fades instead of travelling.