$ git show shake

Error shake

Intermediate/anim shake

Shake an input horizontally when validation fails.

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.

withSequencewithRepeat
shake.tsx · reanimated 4
const x = useSharedValue(0);
const shake = () => {
  x.value = withSequence(
    withTiming(-10, { duration: 50 }),
    withRepeat(withTiming(10, { duration: 100 }), 3, true),
    withTiming(0, { duration: 50 }),
  );
};
const style = useAnimatedStyle(() => ({ transform: [{ translateX: x.value }] }));