
Security News
New React Server Components Vulnerabilities: DoS and Source Code Exposure
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.
@nativescript/canvas
Advanced tools
Powered by
ns plugin add @nativescript/canvas
Note min ios support 11 | min android support 21
IMPORTANT: ensure you include xmlns:canvas="@nativescript/canvas" on the Page element for core {N}
<canvas:Canvas id="canvas" style="width:100%; height:100%" width="100%" height="100%" ready="canvasReady"/>
let ctx;
let canvas;
export function canvasReady(args) {
console.log('canvas ready');
canvas = args.object;
console.log(canvas);
ctx = canvas.getContext('2d');
ctx.fillStyle = 'green';
ctx.fillRect(10, 10, 150, 100);
}
let gl;
let canvas;
export function canvasReady(args) {
console.log('canvas ready');
canvas = args.object;
gl = canvas.getContext('webgl'); // 'webgl' || 'webgl2'
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
// Set the clear color to darkish green.
gl.clearColor(0.0, 0.5, 0.0, 1.0);
// Clear the context with the newly set color. This is
// the function call that actually does the drawing.
gl.clear(gl.COLOR_BUFFER_BIT);
}
Note min ios support 11 | min android support 27
// the webgpu type works as well but these exposes any non standard web api (native)
import type { GPUDevice, GPUAdapter } from '@nativescript/canvas';
import { Screen } from '@nativescript/core';
let canvas;
let device: GPUDevice;
export async function canvasReady(args) {
console.log('canvas ready');
canvas = args.object;
const adapter: GPUAdapter = (await navigator.gpu.requestAdapter()) as never;
device = (await adapter.requestDevice()) as never;
// scaling the canvas to ensure everthing looks crisp
const devicePixelRatio = Screen.mainScreen.scale;
canvas.width = canvas.clientWidth * devicePixelRatio;
canvas.height = canvas.clientHeight * devicePixelRatio;
const context = canvas.getContext('webgpu');
/// configureing the context
// Passing in the following options will aollow the configure method to choose the best configs.
// If unsure about what is supported try the following method
const capabilities = this.getCapabilities(device);
// cap.presentModes
// cap.alphaModes
// cap.format
// cap.usages
context.configure({
device,
format: presentationFormat,
});
/// rendering logic
// to render to your screen you will need to call presentSurfacefrom the WebGPU context.
// Add the followig to the end of your render loop to ensure it gets displayed.
context.presentSurface();
}
FAQs
DOM Canvas API for NativeScript
The npm package @nativescript/canvas receives a total of 438 weekly downloads. As such, @nativescript/canvas popularity was classified as not popular.
We found that @nativescript/canvas demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 18 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.