Skip to main content
Shaders define how pixels are colored when drawing shapes. React Native Skia provides several built-in shaders including gradients, images, and custom runtime shaders.

Linear Gradient

Creates a gradient that transitions colors along a line.
import { Canvas, Rect, LinearGradient, vec } from "@shopify/react-native-skia";

<Canvas style={{ flex: 1 }}>
  <Rect x={0} y={0} width={300} height={300}>
    <LinearGradient
      start={vec(0, 0)}
      end={vec(300, 300)}
      colors={["red", "yellow", "green"]}
    />
  </Rect>
</Canvas>

Props

start
Vector
required
Starting point of the gradient { x: number, y: number }
end
Vector
required
Ending point of the gradient { x: number, y: number }
colors
Color[]
required
Array of colors to transition between
positions
number[]
Optional array of positions (0-1) for each color. If omitted, colors are evenly spaced.
mode
TileMode
default:"'clamp'"
How the gradient extends beyond its bounds:
  • clamp: Uses edge colors
  • repeat: Repeats the gradient
  • mirror: Mirrors the gradient
  • decal: Transparent outside bounds

Radial Gradient

Creates a circular gradient radiating from a center point.
import { Canvas, Circle, RadialGradient, vec } from "@shopify/react-native-skia";

<Canvas style={{ flex: 1 }}>
  <Circle cx={150} cy={150} r={100}>
    <RadialGradient
      c={vec(150, 150)}
      r={100}
      colors={["white", "blue", "navy"]}
    />
  </Circle>
</Canvas>

Props

c
Vector
required
Center point of the gradient { x: number, y: number }
r
number
required
Radius of the gradient
colors
Color[]
required
Array of colors to transition between
positions
number[]
Optional array of positions (0-1) for each color
mode
TileMode
default:"'clamp'"
Tile mode (clamp, repeat, mirror, or decal)

Sweep Gradient

Creates a conical gradient that sweeps around a center point.
import { Canvas, Circle, SweepGradient, vec } from "@shopify/react-native-skia";

<Canvas style={{ flex: 1 }}>
  <Circle cx={150} cy={150} r={100}>
    <SweepGradient
      c={vec(150, 150)}
      colors={["cyan", "magenta", "yellow", "cyan"]}
    />
  </Circle>
</Canvas>

Props

c
Vector
required
Center point of the gradient { x: number, y: number }
colors
Color[]
required
Array of colors to transition between
start
number
default:"0"
Start angle in degrees (0-360)
end
number
default:"360"
End angle in degrees (0-360)
positions
number[]
Optional array of positions (0-1) for each color
mode
TileMode
default:"'clamp'"
Tile mode (clamp, repeat, mirror, or decal)

Two-Point Conical Gradient

Creates a gradient between two circles.
import { Canvas, Rect, TwoPointConicalGradient, vec } from "@shopify/react-native-skia";

<Canvas style={{ flex: 1 }}>
  <Rect x={0} y={0} width={300} height={300}>
    <TwoPointConicalGradient
      start={vec(100, 150)}
      startR={10}
      end={vec(200, 150)}
      endR={100}
      colors={["yellow", "orange", "red"]}
    />
  </Rect>
</Canvas>

Props

start
Vector
required
Center of the start circle
startR
number
required
Radius of the start circle
end
Vector
required
Center of the end circle
endR
number
required
Radius of the end circle
colors
Color[]
required
Array of colors to transition between
positions
number[]
Optional array of positions (0-1) for each color
mode
TileMode
default:"'clamp'"
Tile mode (clamp, repeat, mirror, or decal)

Image Shader

Uses an image as a shader pattern.
import { Canvas, Rect, ImageShader, useImage } from "@shopify/react-native-skia";

export default function ImageShaderExample() {
  const image = useImage(require("./pattern.png"));
  
  if (!image) return null;
  
  return (
    <Canvas style={{ flex: 1 }}>
      <Rect x={0} y={0} width={300} height={300}>
        <ImageShader
          image={image}
          tx="repeat"
          ty="repeat"
          fm="linear"
        />
      </Rect>
    </Canvas>
  );
}

Props

image
SkImage
required
The image to use as a shader
tx
TileMode
default:"'clamp'"
Horizontal tile mode
ty
TileMode
default:"'clamp'"
Vertical tile mode
fm
FilterMode
default:"'linear'"
Filter mode: nearest or linear
fit
Fit
default:"'none'"
How to fit the image: contain, cover, fill, fitHeight, fitWidth, scaleDown, or none

Color Shader

Creates a solid color shader.
import { Canvas, Circle, Color } from "@shopify/react-native-skia";

<Canvas style={{ flex: 1 }}>
  <Circle cx={150} cy={150} r={100}>
    <Color color="purple" />
  </Circle>
</Canvas>

Props

color
Color
required
The solid color to use

Turbulence

Creates turbulent noise patterns.
import { Canvas, Rect, Turbulence } from "@shopify/react-native-skia";

<Canvas style={{ flex: 1 }}>
  <Rect x={0} y={0} width={300} height={300}>
    <Turbulence freqX={0.05} freqY={0.05} octaves={4} seed={2} />
  </Rect>
</Canvas>

Props

freqX
number
required
Base frequency in X direction
freqY
number
required
Base frequency in Y direction
octaves
number
required
Number of octaves of noise
seed
number
required
Random seed for the noise
tileWidth
number
default:"0"
Width for tiling (0 = no tiling)
tileHeight
number
default:"0"
Height for tiling (0 = no tiling)

Fractal Noise

Creates fractal noise patterns (smoother than turbulence).
import { Canvas, Rect, FractalNoise } from "@shopify/react-native-skia";

<Canvas style={{ flex: 1 }}>
  <Rect x={0} y={0} width={300} height={300}>
    <FractalNoise freqX={0.05} freqY={0.05} octaves={4} seed={10} />
  </Rect>
</Canvas>

Props

Same as Turbulence.

Runtime Shader

Create custom shaders using GLSL-like SkSL code.
import { Canvas, Rect, Shader, Skia } from "@shopify/react-native-skia";

const source = Skia.RuntimeEffect.Make(`
  uniform vec2 resolution;
  uniform float time;
  
  half4 main(vec2 fragCoord) {
    vec2 uv = fragCoord / resolution;
    float r = abs(sin(time + uv.x));
    float g = abs(sin(time + uv.y));
    float b = abs(sin(time + uv.x + uv.y));
    return vec4(r, g, b, 1.0);
  }
`);

export default function CustomShader() {
  const time = useSharedValue(0);
  
  useEffect(() => {
    time.value = withRepeat(withTiming(10, { duration: 5000 }), -1);
  }, []);
  
  return (
    <Canvas style={{ flex: 1 }}>
      <Rect x={0} y={0} width={300} height={300}>
        <Shader source={source} uniforms={{ resolution: [300, 300], time }} />
      </Rect>
    </Canvas>
  );
}

Props

source
SkRuntimeEffect
required
Compiled shader created with Skia.RuntimeEffect.Make()
uniforms
Uniforms
required
Object containing uniform values for the shader

Gradient Positions

Control color distribution with positions:
<LinearGradient
  start={vec(0, 0)}
  end={vec(300, 0)}
  colors={["red", "yellow", "green"]}
  positions={[0, 0.2, 1]}  // Yellow appears earlier
/>

Tile Modes

Control how shaders extend beyond their bounds:
// Clamp: extends edge colors
<LinearGradient ... mode="clamp" />

// Repeat: tiles the gradient
<LinearGradient ... mode="repeat" />

// Mirror: mirrors the gradient
<LinearGradient ... mode="mirror" />

// Decal: transparent outside
<LinearGradient ... mode="decal" />

Shader Transformations

Apply transformations to shaders:
import { Canvas, Rect, LinearGradient, vec } from "@shopify/react-native-skia";

<Canvas style={{ flex: 1 }}>
  <Rect x={0} y={0} width={300} height={300}>
    <LinearGradient
      start={vec(0, 0)}
      end={vec(300, 0)}
      colors={["blue", "cyan"]}
      transform={[
        { rotate: Math.PI / 4 },
        { translateX: 50 },
      ]}
    />
  </Rect>
</Canvas>

Build docs developers (and LLMs) love