-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(🎮): add headless app example (#2945)
- Loading branch information
1 parent
53e8fae
commit 484b1b3
Showing
7 changed files
with
304 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## Commands | ||
|
||
**Install Dependencies** | ||
|
||
```console | ||
yarn install | ||
``` | ||
|
||
**Run** | ||
|
||
```console | ||
bun ./src/helloWorld.tsx | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "headless-skia", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"test": "ts-node ./src/helloWorld.tsx", | ||
"tsc": "tsc" | ||
}, | ||
"dependencies": { | ||
"@shopify/react-native-skia": "workspace:*", | ||
"react": "^18.0.0", | ||
"typescript": "^5.2.2" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^9.19.0", | ||
"eslint-config-react-native-wcandillon": "^3.10.2", | ||
"ts-node": "^10.9.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
Circle, | ||
drawOffscreen, | ||
getSkiaExports, | ||
Group, | ||
makeOffscreenSurface, | ||
} from "@shopify/react-native-skia/src/headless"; | ||
import { LoadSkiaWeb } from "@shopify/react-native-skia/src/web/LoadSkiaWeb"; | ||
import React from "react"; | ||
|
||
// https://shopify.github.io/react-native-skia/docs/getting-started/headless/ | ||
(async () => { | ||
const width = 256; | ||
const height = 256; | ||
const size = 60; | ||
const r = size * 0.33; | ||
await LoadSkiaWeb(); | ||
// Once that CanvasKit is loaded, you can access Skia via getSkiaExports() | ||
// Alternatively you can do const {Skia} = require("@shopify/react-native-skia") | ||
const { Skia: _ } = getSkiaExports(); | ||
const surface = makeOffscreenSurface(width, height); | ||
const image = drawOffscreen( | ||
surface, | ||
<Group blendMode="multiply"> | ||
<Circle cx={r} cy={r} r={r} color="cyan" /> | ||
<Circle cx={size - r} cy={r} r={r} color="magenta" /> | ||
<Circle cx={size / 2} cy={size - r} r={r} color="yellow" /> | ||
</Group>, | ||
); | ||
console.log(image.encodeToBase64()); | ||
// Cleaning up CanvasKit resources | ||
image.dispose(); | ||
surface.dispose(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": "eslint-config-react-native-wcandillon/tsconfig.base", | ||
"compilerOptions": { | ||
"target": "es2018", | ||
"module": "commonjs", | ||
"lib": ["es2018", "dom"], | ||
"jsx": "react", | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"rootDir": "./src" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.