Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,25 @@ jobs:
working-directory: packages/skia
run: yarn build && yarn pack

- name: Log package.json before change
working-directory: externals/skia-web-app
run: |
echo "=== package.json BEFORE change ==="
grep -n "@shopify/react-native-skia" package.json || echo "Pattern not found"
echo "=================================="

- name: Update package.json to use local Skia package
working-directory: externals/skia-web-app
run: |
sed -i '' 's/"@shopify\/react-native-skia": "[^"]*"/"@shopify\/react-native-skia": "file:..\/..\/packages\/skia\/package.tgz"/' package.json
# More robust regex that handles different whitespace
sed -i '' 's/"@shopify\/react-native-skia"[[:space:]]*:[[:space:]]*"[^"]*"/"@shopify\/react-native-skia": "file:..\/..\/packages\/skia\/package.tgz"/' package.json

- name: Log package.json after change
working-directory: externals/skia-web-app
run: |
echo "=== package.json AFTER change ==="
grep -n "@shopify/react-native-skia" package.json || echo "Pattern not found"
echo "================================="

- name: Install dependencies for skia-web-app
working-directory: externals/skia-web-app
Expand Down
31 changes: 31 additions & 0 deletions apps/docs/docs/getting-started/web.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,37 @@ LoadSkiaWeb({
});
```

## WebGL Contextes

Web browsers limit the number of WebGL contexts to 16 per webpage.
Usually developers will see this error when they exceed this limit:

```
WARNING: Too many active WebGL contexts. Oldest context will be lost.
```
If you canvas is static and doesn't contain animation values, you can use the `__destroyWebGLContextAfterRender={true}` prop on your Canvas components to destroy the WebGL context after rendering.
This even works with animated canvases but it will come with a performance cost as the context will be recreated on each render.

```tsx twoslash
import { View } from 'react-native';
import { Canvas, Fill } from "@shopify/react-native-skia";

export default function App() {
return (
<View style={{ flex: 1 }}>
{
// 20 Skia Canvases with __destroyWebGLContextAfterRender={true}
new Array(20).fill(0).map((_, i) => (
<Canvas key={i} style={{ width: 100, height: 100 }} __destroyWebGLContextAfterRender={true}>
<Fill color="lightblue" />
</Canvas>
))
}
</View>
);
}
```

## Unsupported Features

The following React Native Skia APIs are currently unsupported on React Native Web.
Expand Down
12 changes: 6 additions & 6 deletions apps/example/src/Tests/Tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const Tests = ({ assets }: TestsProps) => {
const [client, hostname] = useClient();
const [drawing, setDrawing] = useState<any>(null);
const [screen, setScreen] = useState<any>(null);

useEffect(() => {
if (client !== null) {
// Define the message handler as a separate function
Expand Down Expand Up @@ -66,16 +66,16 @@ export const Tests = ({ assets }: TestsProps) => {
};

// Use addEventListener instead of onmessage
client.addEventListener('message', handleMessage);
client.addEventListener("message", handleMessage);

// Clean up: remove the specific event listener
return () => {
client.removeEventListener('message', handleMessage);
client.removeEventListener("message", handleMessage);
};
}
return;
}, [assets, client]);

useEffect(() => {
if (drawing && client) {
const it = setTimeout(() => {
Expand Down Expand Up @@ -104,7 +104,7 @@ export const Tests = ({ assets }: TestsProps) => {
}
return;
}, [client, drawing, ref]);

useEffect(() => {
if (screen && client) {
const it = setTimeout(async () => {
Expand All @@ -120,7 +120,7 @@ export const Tests = ({ assets }: TestsProps) => {
}
return;
}, [client, screen]);

return (
<View style={{ flex: 1, backgroundColor: "white" }}>
<Text style={{ color: "black" }}>
Expand Down
1 change: 1 addition & 0 deletions packages/skia/src/renderer/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
onSize?: SharedValue<SkSize>;
colorSpace?: "p3" | "srgb";
ref?: React.Ref<CanvasRef>;
__destroyWebGLContextAfterRender?: boolean;
}

export const Canvas = ({
Expand Down
Loading
Loading