High-performance React Native Graphics using Skia
Installations
npm install @shopify/react-native-skia
Developer Guide
Typescript
Yes
Module System
CommonJS
Score
69.7
Supply Chain
50.5
Quality
81.2
Maintenance
50
Vulnerability
93.6
License
Releases
Contributors
Languages
TypeScript (63.7%)
C++ (28%)
Objective-C++ (2.46%)
Java (2.14%)
JavaScript (1.14%)
Objective-C (1.02%)
CMake (0.5%)
MDX (0.39%)
Ruby (0.28%)
Kotlin (0.24%)
CSS (0.07%)
C (0.05%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
6,872,942
Last Day
25,771
Last Week
140,607
Last Month
562,215
Last Year
4,945,328
GitHub Statistics
MIT License
7,198 Stars
3,364 Commits
481 Forks
280 Watchers
322 Branches
7,150 Contributors
Updated on Feb 14, 2025
Bundle Size
262.23 kB
Minified
67.53 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.11.7
Package Id
@shopify/react-native-skia@1.11.7
Unpacked Size
402.83 MB
Size
155.23 MB
File Count
4,402
Published on
Feb 12, 2025
Total Downloads
Cumulative downloads
Total Downloads
6,872,942
Last Day
3.8%
25,771
Compared to previous day
Last Week
9.4%
140,607
Compared to previous week
Last Month
38.2%
562,215
Compared to previous month
Last Year
202.9%
4,945,328
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
Peer Dependencies
3
Dev Dependencies
30
React Native Skia
High-performance 2d Graphics for React Native using Skia

Checkout the full documentation here.
React Native Skia brings the Skia Graphics Library to React Native. Skia serves as the graphics engine for Google Chrome and Chrome OS, Android, Flutter, Mozilla Firefox and Firefox OS, and many other products.
Getting Started
Library Development
To develop react-native-skia, you need to build the skia libraries on your computer.
If you have Android Studio installed, make sure $ANDROID_NDK
is available.
ANDROID_NDK=/Users/username/Library/Android/sdk/ndk/<version>
for instance.
If the NDK is not installed, you can install it via Android Studio by going to the menu File > Project Structure.
And then the SDK Location section. It will show you the NDK path, or the option to Download it if you don't have it installed.
Building
- Checkout submodules
git submodule update --init --recursive
- Install dependencies
yarn
- Go to the package folder
cd packages/skia
- Build the Skia libraries with
yarn build-skia
(this can take a while) - Copy Skia headers
yarn copy-skia-headers
- run
yarn pod:install
Upgrading
If a new version of Skia is included in an upgrade of this library, you need to perform a few extra steps before continuing:
- Update submodules:
git submodule update --recursive --remote
- Clean Skia:
yarn clean-skia
- Build Skia:
yarn build-skia
- Copy Skia Headers:
yarn copy-skia-headers
- Run pod install in the example project
Publishing
- Run the commands in the Building section
- Build the Android binaries with
yarn build-skia-android
- Build the NPM package with
yarn build-npm
Publish the NPM package manually. The output is found in the dist
folder.
- Install Cocoapods in the example/ios folder
cd example/ios && pod install && cd ..
Contributing
When making contributions to the project, an important part is testing.
In the package
folder, we have several scripts set up to help you maintain the quality of the codebase and test your changes:
yarn lint
— Lints the code for potential errors and to ensure consistency with our coding standards.yarn tsc
— Runs the TypeScript compiler to check for typing issues.yarn test
— Executes the unit tests to ensure existing features work as expected after changes.yarn e2e
— Runs end-to-end tests. For these tests to run properly, you need to have the example app running. Useyarn ios
oryarn android
in theexample
folder and navigate to the Tests screen within the app.
Running End-to-End Tests
To ensure the best reliability, we encourage running end-to-end tests before submitting your changes:
- Start the example app:
1cd example 2yarn ios # or yarn android for Android testing
Once the app is open in your simulator or device, press the "Tests" item at the bottom of the list.
- With the example app running and the Tests screen open, run the following command in the
package
folder:
1yarn e2e
This will run through the automated tests and verify that your changes have not introduced any regressions. You can also run a particular using the following command:
1E2E=true yarn test -i e2e/Colors
Writing End-to-End Tests
Contributing end-to-end tests to React Native Skia is extremely useful. Below you'll find guidelines for writing tests using the eval
, draw
, and drawOffscreen
commands.
e2e tests are located in the package/__tests__/e2e/
directory. You can create a file there or add a new test to an existing file depending on what is most sensible.
When looking to contribute a new test, you can refer to existing tests to see how these can be built.
The eval
command is used to test Skia's imperative API. It requires a pure function that invokes Skia operations and returns a serialized result.
1it("should generate commands properly", async () => { 2 const result = await surface.eval((Skia) => { 3 const path = Skia.Path.Make(); 4 path.lineTo(30, 30); 5 return path.toCmds(); 6 }); 7 expect(result).toEqual([[0, 0, 0], [1, 30, 30]]); 8});
Both the eval
and draw
commands require a function that will be executed in an isolated context, so the functions must be pure (without external dependencies) and serializable. You can use the second parameter to provide extra data to that function.
1it("should generate commands properly", async () => { 2 // Referencing the SVG variable directly in the tests would fail 3 // as the function wouldn't be able to run in an isolated context 4 const svg = "M 0 0, L 30 30"; 5 const result = await surface.eval((Skia, ctx) => { 6 const path = Skia.Path.MakeFromSVGString(ctx.svg); 7 return path.toCmds(); 8 }, { svg }); 9 expect(result).toEqual([[0, 0, 0], [1, 30, 30]]); 10});
A second option is to use the draw
command where you can test the Skia components and get the resulting image:
1it("Path with default fillType", async () => { 2 const { Skia } = importSkia(); 3 const path = star(Skia); 4 const img = await surface.draw( 5 <> 6 <Fill color="white" /> 7 <Path path={path} style="stroke" strokeWidth={4} color="#3EB489" /> 8 <Path path={path} color="lightblue" /> 9 </> 10 ); 11 checkImage(image, "snapshots/drawings/path.png"); 12});
Finally, you can use drawOffscreen
to receive a canvas object as parameter. You will also get the resulting image:
1 it("Should draw cyan", async () => { 2 const image = await surface.drawOffscreen( 3 (Skia, canvas, { size }) => { 4 canvas.drawColor(Skia.Color("cyan")); 5 } 6 ); 7 checkImage(image, "snapshots/cyan.png"); 8 });
Again, since eval
, draw
, and drawOffscreen
serialize the function's content, avoid any external dependencies that can't be serialized.
Graphite
Skia has two backends: Ganesh and Graphite. Ganesh is the default backend.
Currently, Graphite doesn't match Ganesh in terms of features, but we offer experimental support for it.
If you want to tinker with Graphite, you can enable it by building Skia using SK_GRAPHITE=1 yarn build-skia
.
With this command, the Skia binary will work for both Ganesh and Graphite.
The reason we do not currently ship this build by default is that it requires Android API Level 26 or above.
To enable Graphite in your app, follow these steps:
- iOS: Install pods using
SK_GRAPHITE=1 pod install
. - Android: In CMakeLists.txt, use
set(SK_GRAPHITE ON)
.

No vulnerabilities found.

No security vulnerabilities found.
Other packages similar to @shopify/react-native-skia
react-native-fiesta
A set of celebration animations powered by Skia. Engage more with your users by celebrating in your React Native application.
bunny-react-skia
@shopify/react-native-skia/headless for Edge Scripting for bunny.net 🐰
react-native-skia-ui
Cross platform UI primitives implemented with `@shopify/react-native-skia`
react-native-free-canvas
A high-performance drawing and sketching library for React Native, built on @shopify/react-native-skia, with smooth zoom and pan functionalities.