$ git show shape-morph

Shape morph

Advanced/anim shape-morph

A shape melts smoothly from a circle to a rounded square to an organic blob and back.

Main · New Architecture only · worklets live in react-native-worklets
usePathInterpolationSkia.PathwithRepeat
shape-morph.tsx · reanimated 4
// Unchanged in Reanimated 4: Skia reads the shared value directly
import { Canvas, Path, Skia, usePathInterpolation } from '@shopify/react-native-skia';

const S = 120, k = 0.5523 * (S / 2), m = S / 2;
// Every shape: moveTo + 4 cubicTo + close, so the verbs line up
const circle = Skia.Path.MakeFromSVGString(
  'M ' + m + ' 0 C ' + (m + k) + ' 0 ' + S + ' ' + (m - k) + ' ' + S + ' ' + m +
  ' C ' + S + ' ' + (m + k) + ' ' + (m + k) + ' ' + S + ' ' + m + ' ' + S +
  ' C ' + (m - k) + ' ' + S + ' 0 ' + (m + k) + ' 0 ' + m +
  ' C 0 ' + (m - k) + ' ' + (m - k) + ' 0 ' + m + ' 0 Z');
const square = Skia.Path.MakeFromSVGString(
  'M ' + m + ' 0 C ' + S + ' 0 ' + S + ' 0 ' + S + ' ' + m +
  ' C ' + S + ' ' + S + ' ' + S + ' ' + S + ' ' + m + ' ' + S +
  ' C 0 ' + S + ' 0 ' + S + ' 0 ' + m + ' C 0 0 0 0 ' + m + ' 0 Z');
const blob = Skia.Path.MakeFromSVGString(
  'M 60 6 C 100 0 118 30 112 62 C 106 98 80 118 52 112 C 20 106 0 80 8 50 C 14 24 30 10 60 6 Z');

const t = useSharedValue(0);
useEffect(() => {
  t.value = withRepeat(withTiming(2, { duration: 3000, easing: Easing.inOut(Easing.cubic) }), -1, true);
}, []);

const path = usePathInterpolation(t, [0, 1, 2], [circle, square, blob]);

<Canvas style={{ width: S, height: S }}>
  <Path path={path} color="#2F54EB" />
</Canvas>