$ git show dvd-bounce

DVD logo bounce

Basic/anim dvd-bounce

Bounce a logo off the screen edges forever by running X and Y as two independent ping-pong timings.

Inspired by DVD screensaverFrom 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
withRepeatEasing.linearuseAnimatedReaction
dvd-bounce.tsx · reanimated 4
import { scheduleOnRN } from 'react-native-worklets';

const x = useSharedValue(0), y = useSharedValue(0);
const SPEED = 80; // px per second
useEffect(() => {
  x.value = withRepeat(withTiming(W - LOGO_W, { duration: (W / SPEED) * 1000, easing: Easing.linear }), -1, true);
  y.value = withRepeat(withTiming(H - LOGO_H, { duration: (H / SPEED) * 1000, easing: Easing.linear }), -1, true);
}, []);
// change color on every wall hit
useAnimatedReaction(
  () => x.value <= 0 || x.value >= W - LOGO_W || y.value <= 0 || y.value >= H - LOGO_H,
  (hit, prev) => { if (hit && !prev) scheduleOnRN(nextColor); },
);
const style = useAnimatedStyle(() => ({ transform: [{ translateX: x.value }, { translateY: y.value }] }));