nativescript-community / ui-canvas

Implement Canvas into your NativeScript apps.
https://nativescript-community.github.io/ui-canvas/
Apache License 2.0
31 stars 9 forks source link

Nativescript Core examples #50

Open glorious73 opened 5 months ago

glorious73 commented 5 months ago

I could not find a demo for Nativescript core so I created one (to save time for others). It draws both a simple black rectangle on a page and an svg from a certain source.


## `ui-canvas` example

- app-root.xml
```xml
<Frame defaultPage="~/views/welcome/welcome-page" id="topmost"></Frame>

const { WelcomeViewModel } = require("./welcome-view-model");

const welcomeViewModel = new WelcomeViewModel();

export const onLoaded = (args) => { const page = args.object; page.bindingContext = welcomeViewModel; };

export const onDraw = (event) => { try { const paint = new Paint(); paint.setColor(new Color('black')); paint.strokeWidth = 10; event.canvas.drawRect(createRect(0, 0, 400, 400), paint); } catch(err) { console.log(err); } }


## `ui-svg` example
- Same file structure as above.
- Note that you need to install `@nativescript-community/arraybuffers`, `@nativescript-community/canvas`, and `@nativescript-community/ui-svg` to avoid dependency-related errors. Also, no need for the use of Javascript since we are directly using `SVGView`.

- app-root.xml
```xml
<Frame defaultPage="~/views/welcome/welcome-page" id="topmost"></Frame>
farfromrefug commented 5 months ago

@glorious73 awesome will add it to the readme!