$ git show wallet-stack

Wallet card stack

Advanced/anim wallet-stack

Tap a card in a stack: it rises to the top and the rest collapse to the bottom.

Inspired by Apple WalletFrom William Candillon’s “Can it be done in React Native?” series. The code here is a simplified rewrite for Reanimated 4 and 3.
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.

withSpringGesture.Tapderived layout
wallet-stack.tsx · reanimated 4
const selected = useSharedValue(-1);
function Card({ index }) {
  const style = useAnimatedStyle(() => {
    const s = selected.value, isSel = s === index;
    const y = s === -1 ? index * PEEK
      : isSel ? 0
      : height - 160 + (index - (index > s ? 1 : 0)) * 8; // collapsed pile at the bottom
    return {
      zIndex: isSel ? 100 : index,
      transform: [
        { translateY: withSpring(y, { damping: 18 }) },
        { scale: withSpring(s === -1 || isSel ? 1 : 0.92) },
      ],
    };
  });
  const tap = Gesture.Tap().onEnd(() => { selected.value = selected.value === index ? -1 : index; });
  return <GestureDetector gesture={tap}><Animated.View style={[styles.card, style]} /></GestureDetector>;
}