Class “Canvas”

Object > NativeObject > Widget > Composite > Canvas

Canvas is a widget that can be used to draw graphics using a canvas context.

Canvas on Android
Canvas on iOS
Constructor public
Singleton No
Namespace tabris
Direct subclasses None
JSX support Element: <Canvas/>
Parent element: <Composite/> and any widget extending Composite
Child elements: Widgets
Text content: Not supported


import {Canvas, contentView} from 'tabris';

new Canvas({layoutData: 'fill'})
  .onResize(({target: canvas, width, height}) => {
    let context = canvas.getContext("2d", width, height);
    context.moveTo(0, 0);
    // ...

See also:


new Canvas(properties?)

Parameter Type Optional Description
properties Properties<Canvas> Yes Sets all key-value pairs in the properties object as widget properties.


getContext(contextType, width, height)

Returns the drawing context with the given size.

Parameter Type Optional Description
contextType string No The context identifier. Only "2d" is currently supported.
width number No the width of the canvas context to create
height number No the height of the canvas context to create

Returns CanvasContext