$ git show tilt-card
3D tilt card
Press and move your finger on a card and it tilts toward you in 3D with a sliding glare, then springs flat.
// Unchanged in Reanimated 4: the finger position drives the tilt directly
const W = 260, H = 160, MAX = 12; // degrees
const rx = useSharedValue(0), ry = useSharedValue(0);
const glareX = useSharedValue(W / 2);
const pan = Gesture.Pan()
.minDistance(0)
.onUpdate((e) => {
ry.value = interpolate(e.x, [0, W], [-MAX, MAX], Extrapolation.CLAMP);
rx.value = interpolate(e.y, [0, H], [MAX, -MAX], Extrapolation.CLAMP);
glareX.value = e.x;
})
.onFinalize(() => {
rx.value = withSpring(0, { damping: 10 });
ry.value = withSpring(0, { damping: 10 });
});
const card = useAnimatedStyle(() => ({
transform: [
{ perspective: 600 },
{ rotateX: rx.value + 'deg' },
{ rotateY: ry.value + 'deg' },
{ scale: withSpring(rx.value || ry.value ? 1.04 : 1) },
],
}));
const glare = useAnimatedStyle(() => ({
opacity: interpolate(Math.abs(rx.value) + Math.abs(ry.value), [0, MAX * 2], [0, 0.35]),
transform: [{ translateX: glareX.value - W }],
}));
<GestureDetector gesture={pan}>
<Animated.View style={[styles.card, { width: W, height: H, overflow: 'hidden' }, card]}>
<CardContent />
{/* A white diagonal band that slides with the finger */}
<Animated.View pointerEvents="none" style={[styles.glare, glare]} />
</Animated.View>
</GestureDetector>