$ git show card-flip

3D card flip

Advanced/anim card-flip

Flip a card to show its back face, using perspective and backface hiding.

Main · New Architecture only · worklets live in react-native-worklets

This snippet uses APIs that didn’t change between versions, so the same code runs on Reanimated 4 and 3.

rotateYperspectivebackfaceVisibility
card-flip.tsx · reanimated 4
const r = useSharedValue(0);
const flip = () => { r.value = withTiming(r.value ? 0 : 180, { duration: 500 }); };
const front = useAnimatedStyle(() => ({
  transform: [{ perspective: 800 }, { rotateY: r.value + 'deg' }],
  backfaceVisibility: 'hidden',
}));
const back = useAnimatedStyle(() => ({
  transform: [{ perspective: 800 }, { rotateY: r.value + 180 + 'deg' }],
  backfaceVisibility: 'hidden',
}));
// stack both faces with position: 'absolute'