$ git show image-compare

Before / after slider

Intermediate/anim image-compare

Drag a divider across two stacked images to reveal more of the edited version.

Main · New Architecture only · worklets live in react-native-worklets
Gesture.PanuseAnimatedStyleoverflow hidden
image-compare.tsx · reanimated 4
// Unchanged in Reanimated 4: the divider is driven by a gesture
const { width: W } = useWindowDimensions();
const x = useSharedValue(W / 2);

const pan = Gesture.Pan()
  .onBegin((e) => { x.value = Math.min(Math.max(e.x, 0), W); }) // tap to jump
  .onChange((e) => { x.value = Math.min(Math.max(x.value + e.changeX, 0), W); });

const clip = useAnimatedStyle(() => ({ width: x.value }));
const handle = useAnimatedStyle(() => ({ transform: [{ translateX: x.value - 20 }] }));

<GestureDetector gesture={pan}>
  <View style={{ width: W, height: H }}>
    <Image source={before} style={StyleSheet.absoluteFill} />
    <Animated.View style={[{ position: 'absolute', top: 0, bottom: 0, left: 0, overflow: 'hidden' }, clip]}>
      {/* Fixed full width so the image doesn't squash as its container narrows */}
      <Image source={after} style={{ width: W, height: H }} />
    </Animated.View>
    <Animated.View style={[styles.handle, handle]}> {/* 40 wide, full height; 2px line + round grip */}
      <View style={styles.line} />
      <View style={styles.grip}><Text>‹ ›</Text></View>
    </Animated.View>
  </View>
</GestureDetector>