$ git show menu-morph
Menu icon morph
Three hamburger lines morph into a close X: the middle fades, the outer two rotate.
// Reanimated 4: CSS transitions react to the open state
const [open, setOpen] = useState(false);
const line = {
width: 28, height: 3, borderRadius: 2, backgroundColor: '#111',
transitionProperty: ['transform', 'opacity'],
transitionDuration: '250ms',
transitionTimingFunction: 'ease-in-out',
} as const;
// Lines are 3 px tall with a 6 px gap, so the outer ones travel 9 px to the middle
<Pressable onPress={() => setOpen(o => !o)} hitSlop={12} style={{ gap: 6 }}>
<Animated.View style={[line, { transform: [{ translateY: open ? 9 : 0 }, { rotate: open ? '45deg' : '0deg' }] }]} />
<Animated.View style={[line, { opacity: open ? 0 : 1 }]} />
<Animated.View style={[line, { transform: [{ translateY: open ? -9 : 0 }, { rotate: open ? '-45deg' : '0deg' }] }]} />
</Pressable>