Skip to content
HTML5-like 2D and WebGL canvas implementation for NativeScript
Objective-C TypeScript Vue Other
Branch: master
Clone or download
Pull request Compare This branch is 47 commits ahead of NativeScript:master.
Latest commit 7cdbee8 Jul 6, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github working android Feb 7, 2019
demo-vue test: updated demo app Jun 13, 2019
plugin v2.1.8 Jul 6, 2019
src-native/ios
src fix: correctly draw images on ios Jun 13, 2019
.gitignore chore: ingore plugin files Jun 13, 2019
.prettierrc working android Feb 7, 2019
.travis.yml working android Feb 7, 2019
CHANGELOG.md v2.1.8 Jul 6, 2019
LICENSE working android Feb 7, 2019
README.md Update README.md Jun 11, 2019
lerna.json v2.1.8 Jul 6, 2019
package.json chore: no native android for now Jun 13, 2019
references.d.ts working android Feb 7, 2019
tsconfig.json chore: dont remove ts comments (future esnext) Jun 13, 2019
tslint.json working android Feb 7, 2019

README.md

npm npm GitHub forks GitHub stars

Installation

  • tns plugin add nativescript-canvas

Be sure to run a new build after adding plugins to avoid any issues.


Usage

The nativescript Canvas is based on the Android Canvas class. The android API is actually a direct subclass with some Additions

Plain NativeScript

IMPORTANT: Make sure you include xmlns:mdc="nativescript-canvas" on the Page element

XML

<Page xmlns:cv="nativescript-canvas">
    <StackLayout horizontalAlignment="center">
        <cv:CanvasView width="100" height="100" draw="draw"/>
   </StackLayout>
</Page>

NativeScript + Angular

import { registerElement } from 'nativescript-angular/element-registry';
import { CanvasView } from 'nativescript-canvas';
registerElement('CanvasView', () => CanvasView);
<CanvasView width="100" height="100" (draw)="draw($event)></CanvasView>

NativeScript + Vue

import Vue from 'nativescript-vue';
import CanvasPlugin from 'nativescript-canvas/vue';

Vue.use(CanvasPlugin);
<CanvasView  width="100" height="100" @draw="draw"/>

##draw Method

function draw(event: { canvas: Canvas }) {
    const paint = new Paint();
    paint.setColor(new Color('black'));
    paint.strokeWidth = 10;
    canvas.drawRect(createRect(0, 0, 200, 100), paint);
}
You can’t perform that action at this time.