$ git show accordion

Accordion

Intermediate/anim accordion

Expand and collapse content to its measured height, with a rotating chevron.

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.

measureuseDerivedValue
accordion.tsx · reanimated 4
const open = useSharedValue(false);
const height = useSharedValue(0);
const progress = useDerivedValue(() => withTiming(open.value ? 1 : 0));
const body = useAnimatedStyle(() => ({ height: height.value * progress.value, overflow: 'hidden' }));
const chevron = useAnimatedStyle(() => ({ transform: [{ rotate: progress.value * 180 + 'deg' }] }));
// inner content:
<View onLayout={e => (height.value = e.nativeEvent.layout.height)} style={{ position: 'absolute' }}>
  {children}
</View>