Skip to content

Commit 8f10624

Browse files
authored
Merge pull request #51 from jasongitmail/patch-1
Update blueprint.md - Add Svelte usage for `ui-canvas`
2 parents a35f908 + d4dffcd commit 8f10624

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

packages/ui-canvas/blueprint.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,30 @@ Vue.use(CanvasPlugin);
5454
<CanvasView width="100" height="100" @draw="draw"/>
5555
```
5656
57+
## NativeScript + Svelte
58+
59+
```ts
60+
// app/app.ts
61+
import { registerNativeViewElement } from 'svelte-native/dom';
62+
registerNativeViewElement('canvasView', () => require('@nativescript-community/ui-canvas').CanvasView);
63+
```
64+
65+
```svelte
66+
<!-- app/components/Foo.svelte -->
67+
<stackLayout>
68+
<canvasView width="300" height="300" on:draw={draw} />
69+
</stackLayout>
70+
```
71+
5772
## Draw Method
58-
```typescript
73+
74+
```ts
75+
import type { Canvas } from '@nativescript-community/ui-canvas';
76+
import { Paint, createRect } from '@nativescript-community/ui-canvas';
77+
import { Color } from '@nativescript/core';
78+
5979
function draw(event: { canvas: Canvas }) {
80+
const canvas = event.canvas;
6081
const paint = new Paint();
6182
paint.setColor(new Color('black'));
6283
paint.strokeWidth = 10;
@@ -78,4 +99,4 @@ function draw(event: { canvas: Canvas }) {
7899
- An example of animating a shape
79100
80101
{{ load:../../tools/readme/demos-and-development.md }}
81-
{{ load:../../tools/readme/questions.md }}
102+
{{ load:../../tools/readme/questions.md }}

0 commit comments

Comments
 (0)