Skip to content

Instantly share code, notes, and snippets.

@DenisDov
Last active January 15, 2024 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DenisDov/5abeecda5184c9e2916af092818d628e to your computer and use it in GitHub Desktop.
Save DenisDov/5abeecda5184c9e2916af092818d628e to your computer and use it in GitHub Desktop.
React Native Skia umbrella
const RADIUS = 100;
const NUM_SLICES = 8;
const renderPath = () => {
const sliceAngle = (2 * Math.PI) / NUM_SLICES;
const paths = [];
const colors = [
"#FF5733",
"#FFC300",
"#36A2EB",
"#4CAF50",
"#FF6384",
"#9966FF",
"#FF9800",
"#8E44AD",
];
for (let i = 0; i < NUM_SLICES; i++) {
const startAngle = i * sliceAngle;
const endAngle = (i + 1) * sliceAngle;
const path = Skia.Path.Make();
path.moveTo(RADIUS, RADIUS);
path.lineTo(
RADIUS + RADIUS * Math.cos(startAngle),
RADIUS + RADIUS * Math.sin(startAngle)
);
path.lineTo(
RADIUS + RADIUS * Math.cos(endAngle),
RADIUS + RADIUS * Math.sin(endAngle)
);
path.close();
paths.push({ path, color: colors[i] });
}
return paths.map((pathData, index) => (
<Path key={index} path={pathData.path} color={pathData.color} />
));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment