$ git show mini-player
Mini to full player
A mini player bar expands into a full-screen player by dragging, and snaps open or closed.
Inspired by SpotifyFrom William Candillon’s “Can it be done in React Native?” series. The code here is a simplified rewrite for Reanimated 4 and 3.
This snippet uses APIs that didn’t change between versions, so the same code runs on Reanimated 4 and 3.
const CLOSED = height - MINI_H, OPEN = 0;
const y = useSharedValue(CLOSED), start = useSharedValue(0);
const pan = Gesture.Pan()
.onStart(() => { start.value = y.value; })
.onUpdate(e => { y.value = clamp(start.value + e.translationY, OPEN, CLOSED); })
.onEnd(e => {
const dest = e.velocityY < -500 || y.value < CLOSED / 2 ? OPEN : CLOSED;
y.value = withSpring(dest, { damping: 20, velocity: e.velocityY });
});
const sheet = useAnimatedStyle(() => ({ transform: [{ translateY: y.value }] }));
const mini = useAnimatedStyle(() => ({
opacity: interpolate(y.value, [CLOSED - 120, CLOSED], [0, 1], Extrapolation.CLAMP),
}));
const full = useAnimatedStyle(() => ({
opacity: interpolate(y.value, [OPEN, CLOSED - 120], [1, 0], Extrapolation.CLAMP),
}));