+1 (415) 943-4271

Custom Graphics in React Native with Skia: Charts, Shaders, and Staying at 60 fps

When Views Run Out

Most React Native UI is built from views and styles. Some features push past that: custom charts, image filters, gradients with blur, signature pads, game-like visuals. Stacking hundreds of Views for these is slow and awkward. @shopify/react-native-skia exposes the Skia graphics engine (the same one behind Chrome and Flutter) as a declarative canvas.

This tutorial builds an animated line chart and covers the habits that keep it smooth. Check the library's docs for the version that matches your React Native and Expo SDK before installing.

Setup

npx expo install @shopify/react-native-skia react-native-reanimated

Skia needs native code, so use a development build rather than Expo Go.

A First Canvas

import { Canvas, Circle, Group, LinearGradient, vec } from '@shopify/react-native-skia';

export function Badge() {
  return (
    <Canvas style={{ width: 120, height: 120 }}>
      <Group>
        <Circle cx={60} cy={60} r={50}>
          <LinearGradient start={vec(0, 0)} end={vec(120, 120)} colors={['#4f46e5', '#06b6d4']} />
        </Circle>
      </Group>
    </Canvas>
  );
}

Everything inside Canvas is a Skia node, not a React Native view. Normal components cannot be nested inside it.

Drawing a Line Chart

Skia has a Path primitive. Build the path from your data once, and memoize it.

import { Canvas, Path, Skia } from '@shopify/react-native-skia';
import { useMemo } from 'react';

type Props = { data: number[]; width: number; height: number };

export function LineChart({ data, width, height }: Props) {
  const path = useMemo(() => {
    const p = Skia.Path.Make();
    const max = Math.max(...data);
    const min = Math.min(...data);
    const span = max - min || 1;
    data.forEach((v, i) => {
      const x = (i / (data.length - 1)) * width;
      const y = height - ((v - min) / span) * height;
      i === 0 ? p.moveTo(x, y) : p.lineTo(x, y);
    });
    return p;
  }, [data, width, height]);

  return (
    <Canvas style={{ width, height }}>
      <Path path={path} style="stroke" strokeWidth={3} color="#4f46e5" strokeJoin="round" />
    </Canvas>
  );
}

Animating with Reanimated

Skia accepts Reanimated shared values directly as props, so animation runs on the UI thread without re-rendering React.

import { Canvas, Path, Skia } from '@shopify/react-native-skia';
import { useEffect } from 'react';
import { useSharedValue, withTiming } from 'react-native-reanimated';

export function AnimatedLine({ path }: { path: ReturnType<typeof Skia.Path.Make> }) {
  const progress = useSharedValue(0);
  useEffect(() => {
    progress.value = withTiming(1, { duration: 900 });
  }, [path]);

  return (
    <Canvas style={{ width: 320, height: 180 }}>
      <Path path={path} style="stroke" strokeWidth={3} color="#4f46e5" start={0} end={progress} />
    </Canvas>
  );
}

The end prop trims the path, which gives a draw-on effect with no per-frame JS.

Touch Interaction

Combine Gesture Handler with a shared value for a scrubber: update an x shared value in onUpdate, and derive the marker position with useDerivedValue. Because both live on the UI thread, the marker tracks your finger without bridge round trips.

Performance Habits

  • Memoize paths. Rebuilding a path every render is the most common cause of dropped frames.
  • Animate values, not state. If setState fires every frame, you've lost the benefit.
  • Keep canvases small. A full-screen canvas for a small chart wastes fill rate.
  • Reuse paints and images. Load images once with useImage, not per render.
  • Downsample data. A thousand points on a 320 px wide chart is invisible detail; reduce before drawing.
  • Profile on a low-end Android device. Simulators hide GPU limits.

Accessibility

A canvas is opaque to screen readers. Wrap it in a view with an accessibilityLabel summarizing the data ("Revenue up 12% over 30 days"), and offer a table or text alternative for detailed values.

When Not to Use Skia

For simple shapes, react-native-svg is often enough and easier to style and make accessible. Choose Skia when you need shaders, blur and filters, very large numbers of elements, or smooth animation of complex paths.

Takeaways

Skia turns heavy visual features into a few declarative nodes. Memoize geometry, animate with shared values, and test on weak hardware. If your team needs help building graphics-heavy features or auditing performance, get in touch.