-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c86c6fa
commit f6dc189
Showing
74 changed files
with
1,812 additions
and
382 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
id: image-svg | ||
title: Image SVG | ||
sidebar_label: SVG | ||
slug: /images-svg | ||
--- | ||
|
||
Draw an SVG | ||
|
||
| Name | Type | Description | | ||
|:----------|:----------|:--------------------------------------------------------------| | ||
| source | `require` or `string` | Source of the SVG or an HTTP(s) URL. | | ||
| width? | `number` | Width of the destination image. | | ||
| height? | `number` | Height of the destination image. | | ||
|
||
### Example | ||
|
||
```tsx twoslash | ||
import { | ||
Canvas, | ||
ImageSVG, | ||
useSVG | ||
} from "@shopify/react-native-skia"; | ||
|
||
const ImageSVGDemo = () => { | ||
// Alternatively, you can pass an image URL directly | ||
// for instance: const source = useSVG("https://upload.wikimedia.org/wikipedia/commons/f/fd/Ghostscript_Tiger.svg"); | ||
const source = useSVG(require("../../assets/tiger.svg")); | ||
return ( | ||
<Canvas style={{ flex: 1 }}> | ||
{ source && ( | ||
<ImageSVG | ||
source={source} | ||
width={256} | ||
height={256} | ||
/>) | ||
} | ||
</Canvas> | ||
); | ||
}; | ||
``` |
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
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,52 @@ | ||
--- | ||
id: fonts | ||
title: Fonts | ||
sidebar_label: Fonts | ||
slug: /text/fonts | ||
--- | ||
|
||
By default all the fonts available within your app are available in your Canvas. For instance, you can write the following. | ||
|
||
```tsx twoslash | ||
import {Canvas, Text} from "@shopify/react-native-skia"; | ||
|
||
export const HelloWorld = () => { | ||
return ( | ||
<Canvas style={{ flex: 1 }}> | ||
<Text | ||
x={0} | ||
y={0} | ||
value="Hello World" | ||
familyName="serif" | ||
size={16} | ||
/> | ||
</Canvas> | ||
); | ||
}; | ||
``` | ||
|
||
Alternatively, you can use your own set of custom fonts to be available in the canvas, as seen below. | ||
|
||
```tsx twoslash | ||
import {Canvas, Text, useFontMgr} from "@shopify/react-native-skia"; | ||
|
||
export const HelloWorld = () => { | ||
const fontMgr = useFontMgr([ | ||
require("./my-custom-font.otf") | ||
]); | ||
if (fontMgr === null) { | ||
return null; | ||
} | ||
return ( | ||
<Canvas style={{ flex: 1 }} fontMgr={fontMgr}> | ||
<Text | ||
x={0} | ||
y={0} | ||
value="Hello World" | ||
familyName="My Custom Font" | ||
size={16} | ||
/> | ||
</Canvas> | ||
); | ||
}; | ||
``` |
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,36 @@ | ||
--- | ||
id: text | ||
title: Text | ||
sidebar_label: Text | ||
slug: /text/text | ||
--- | ||
|
||
The text component can be used to draw a simple text. | ||
The font family and the font size must be specified. | ||
The fonts available in the canvas are described in [here](/docs/text/fonts). | ||
|
||
| Name | Type | Description | | ||
|:-----------|:----------|:--------------------------------------------------------------| | ||
| value | `string` | Text to draw | | ||
| familyName | `string` | Font family name | | ||
| size | `number` | Font size | | ||
|
||
### Example | ||
|
||
```tsx twoslash | ||
import {Canvas, Text} from "@shopify/react-native-skia"; | ||
|
||
export const HelloWorld = () => { | ||
return ( | ||
<Canvas style={{ flex: 1 }}> | ||
<Text | ||
x={0} | ||
y={0} | ||
value="Hello World" | ||
familyName="serif" | ||
size={32} | ||
/> | ||
</Canvas> | ||
); | ||
}; | ||
``` |
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
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 |
---|---|---|
|
@@ -687,4 +687,4 @@ | |
/* End XCConfigurationList section */ | ||
}; | ||
rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */; | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -8,4 +8,5 @@ export type Routes = { | |
Transform: undefined; | ||
ColorFilter: undefined; | ||
Gradients: undefined; | ||
SVG: undefined; | ||
}; |
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,23 @@ | ||
import React from "react"; | ||
import { Dimensions } from "react-native"; | ||
import { Canvas, ImageSVG, useSVG } from "@shopify/react-native-skia"; | ||
|
||
const { width, height } = Dimensions.get("window"); | ||
|
||
export const SVG = () => { | ||
const svg = useSVG(require("./tiger.svg")); | ||
if (svg === null) { | ||
return null; | ||
} | ||
return ( | ||
<Canvas style={{ flex: 1 }}> | ||
<ImageSVG | ||
source={svg} | ||
x={0} | ||
y={0} | ||
width={width / 2} | ||
height={height / 2} | ||
/> | ||
</Canvas> | ||
); | ||
}; |
Oops, something went wrong.