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.
One field, a lot of ways to go wrong
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.
One transform for everything
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.
const sheetStyle = useAnimatedStyle(() => ({
opacity: opacity.get(),
transform: [
{
translateY:
Math.max(offset.get(), 0) +
Math.min(0, keyboard.height.get() + WINDOW_BOTTOM),
},
],
}));The keyboard covers the home indicator area too, and the drawer already pads itself by that inset, so the inset is added back before the drawer moves; otherwise it floats one indicator-height above the keys. That inset comes from the window, not the screen. Opened from a tab, the screen's safe area also counts the tab bar, and the first version stood 49 points too tall on the iPhone because of it.
Measured, and it never shrinks
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.
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();
}
};Flicks, and a fast way out
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.
.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 }),
);
}
});It opens on a spring but leaves on a timed slide: 240 ms, shorter when it's flung, so it carries the speed of your finger off the screen. That wasn't for looks. A spring keeps settling for a while after it looks done, the modal stayed up until it finished, and the first tap after closing was being swallowed. With a timed exit the window closes the moment the drawer is gone.
Honest states
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.