Skip to main content

Gradients

Common Properties

Below are the properties common to all gradient components.

NameTypeDescription
colorsstring[]Colors to be distributed between start and end.
positions?number[]The relative positions of colors. If supplied, it must be of the same length as colors.
mode?TileModeCan be clamp, repeat, mirror, or decal.
flags?numberBy default, gradients will interpolate their colors in unpremultiplied space and then premultiply each of the results. By setting this to 1, the gradients will premultiply their colors first and then interpolate between them.
transform?Transforms2dsee transformations.

Linear Gradient

Returns a shader that generates a linear gradient between the two specified points.

NameTypeDescription
startPointStart position of the gradient.
endPointEnd position of the gradient.

Example

tsx
import React from "react";
import {
Canvas,
Rect,
LinearGradient,
Skia,
Shader,
vec
} from "@shopify/react-native-skia";
 
export const LinearGradientDemo = () => {
return (
<Canvas style={{ flex: 1 }}>
<Rect x={0} y={0} width={256} height={256}>
<LinearGradient
start={vec(0, 0)}
end={vec(256, 256)}
colors={["blue", "yellow"]}
/>
</Rect>
</Canvas>
);
};
tsx
import React from "react";
import {
Canvas,
Rect,
LinearGradient,
Skia,
Shader,
vec
} from "@shopify/react-native-skia";
 
export const LinearGradientDemo = () => {
return (
<Canvas style={{ flex: 1 }}>
<Rect x={0} y={0} width={256} height={256}>
<LinearGradient
start={vec(0, 0)}
end={vec(256, 256)}
colors={["blue", "yellow"]}
/>
</Rect>
</Canvas>
);
};

Result

Linear Gradient

Radial Gradient

Returns a shader that generates a radial gradient given the center and radius.

NameTypeDescription
cPointCenter of the gradient.
rnumberRadius of the gradient.

Example

tsx
import React from "react";
import {
Canvas,
Rect,
RadialGradient,
Skia,
Shader,
vec
} from "@shopify/react-native-skia";
 
export const RadialGradientDemo = () => {
return (
<Canvas style={{ flex: 1 }}>
<Rect x={0} y={0} width={256} height={256}>
<RadialGradient
c={vec(128, 128)}
r={128}
colors={["blue", "yellow"]}
/>
</Rect>
</Canvas>
);
};
tsx
import React from "react";
import {
Canvas,
Rect,
RadialGradient,
Skia,
Shader,
vec
} from "@shopify/react-native-skia";
 
export const RadialGradientDemo = () => {
return (
<Canvas style={{ flex: 1 }}>
<Rect x={0} y={0} width={256} height={256}>
<RadialGradient
c={vec(128, 128)}
r={128}
colors={["blue", "yellow"]}
/>
</Rect>
</Canvas>
);
};

Result

Radial Gradient

Two Point Conical Gradient

Returns a shader that generates a conical gradient given two circles.

NameTypeDescription
startPointCenter of the start circle.
startRnumberRadius of the start circle.
endnumberCenter of the end circle.
endRnumberRadius of the end circle.

Example

tsx
import React from "react";
import {
Canvas,
Rect,
TwoPointConicalGradient,
Skia,
Shader,
vec
} from "@shopify/react-native-skia";
 
export const TwoPointConicalGradientDemo = () => {
return (
<Canvas style={{ flex: 1 }}>
<Rect x={0} y={0} width={256} height={256}>
<TwoPointConicalGradient
start={vec(128, 128)}
startR={128}
end={vec(128, 16)}
endR={16}
colors={["blue", "yellow"]}
/>
</Rect>
</Canvas>
);
};
tsx
import React from "react";
import {
Canvas,
Rect,
TwoPointConicalGradient,
Skia,
Shader,
vec
} from "@shopify/react-native-skia";
 
export const TwoPointConicalGradientDemo = () => {
return (
<Canvas style={{ flex: 1 }}>
<Rect x={0} y={0} width={256} height={256}>
<TwoPointConicalGradient
start={vec(128, 128)}
startR={128}
end={vec(128, 16)}
endR={16}
colors={["blue", "yellow"]}
/>
</Rect>
</Canvas>
);
};

Result

Two Point Conical Gradient

Sweep Gradient

Returns a shader that generates a sweep gradient given a center.

NameTypeDescription
cPointCenter of the gradient
start?numberStart angle in degrees (default is 0).
end?numberEnd angle in degrees (default is 360).

Example

tsx
import React from "react";
import {
Canvas,
Rect,
SweepGradient,
Skia,
Shader,
vec
} from "@shopify/react-native-skia";
 
export const SweepGradientDemo = () => {
return (
<Canvas style={{ flex: 1 }}>
<Rect x={0} y={0} width={256} height={256}>
<SweepGradient
c={vec(128, 128)}
colors={["cyan", "magenta", "yellow", "cyan"]}
/>
</Rect>
</Canvas>
);
};
tsx
import React from "react";
import {
Canvas,
Rect,
SweepGradient,
Skia,
Shader,
vec
} from "@shopify/react-native-skia";
 
export const SweepGradientDemo = () => {
return (
<Canvas style={{ flex: 1 }}>
<Rect x={0} y={0} width={256} height={256}>
<SweepGradient
c={vec(128, 128)}
colors={["cyan", "magenta", "yellow", "cyan"]}
/>
</Rect>
</Canvas>
);
};

Result

Sweep Gradient