Home

Awesome

react-skia-fiber

A React renderer for Skia

Setup

npm install react-skia-fiber

Usage

import React, { useEffect, useState } from "react";
import { SkParagraph } from "react-skia-fiber";

export default function App() {
  const paragraphRef = React.useRef<SkParagraph>();
  const [color, setColor] = useState("red");

  useEffect(() => {
    let colors = ["red", "green", "blue"];
    let i = 0;
    let interval = setInterval(() => {
      i++;
      setColor(colors[i % 3]);
    }, 1_000);
    return () => clearInterval(interval);
  }, []);

  return (
    <skCanvas clear="#ABACAB">
      <skParagraph
        x={100}
        y={100}
        width={500}
        ref={paragraphRef}
        text={color}
      />
      <skText x={100} y={100} text={color} />
    </skCanvas>
  );
}

Roadmap

Docs

Paint Ownership

react-skia-fiber objects can own their own paints:

<skPath svg="..." />
<skPath paint={{ style: "fill" }} />

If paints are passed as props they no longer own their paints. Deallocation of borrowed paints is owned by the environment that initialized the paints.

<skPath paint={myPaint} ... />

Demos

yarn parcel demos/moving-rects/index.html
yarn parcel demos/circular-moving-rects/index.html