Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rax-canvas

Package Overview
Dependencies
Maintainers
5
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rax-canvas

Canvas for Rax.

  • 2.1.0
  • npm
  • Socket score

Version published
Weekly downloads
10
decreased by-16.67%
Maintainers
5
Weekly downloads
 
Created
Source

npm

描述

画布组件.

  • 在 Weex 上依赖 gcanvas
  • 在支付宝小程序中依赖 canvas

安装

$ npm install rax-canvas --save

属性

注: 1、支持列表中的 browser代表 Web weex代表 Weex miniApp代表阿里小程序wechatMiniprogram代表微信小程序

属性类型默认值必填描述支持
styleObject-通过内联的方式设置画布样式browser weexminiAppwechatMiniprogram
classNameObject-设置画布的样式browser weexminiAppwechatMiniprogram
widthnumber0设置画布的宽度browser weexminiAppwechatMiniprogram
heightnumber0设置画布的高度browser weexminiAppwechatMiniprogram
onClickfunction-点击画布时触发的事件browser weexminiAppwechatMiniprogram
onLongPressfunction-长按画布时触发的事件browser weexminiAppwechatMiniprogram
onTouchStartfunction-触摸画布时触发的事件browser weexminiAppwechatMiniprogram
onTouchMovefunction-手指在画布上移动时触发的事件browser weexminiAppwechatMiniprogram
onTouchEndfunction-结束触摸时触发的事件browser weexminiAppwechatMiniprogram
onTouchCancelfunction-触摸事件取消的时候触发的事件browser weexminiAppwechatMiniprogram

方法

getContext(type: string)

返回画布实例。

type 默认值为 2d,目前在微信小程序中仅支持 2d/webgl,在阿里小程序中暂不支持设置。

注意

直接指定 width 或者 height 的优先级高于在 styleclassName 中指定的宽高。

示例

import { createElement, Component, render, createRef } from 'rax';
import Canvas from 'rax-canvas';
import DriverUniversal from "driver-universal"

class CanvasSample extends Component {
  constructor(props) {
    super(props);
    this.raxCanvasDemo = createRef()
  }
  componentDidMount() {
    const context = this.raxCanvasDemo.current.getContext();
    context.fillStyle = 'red';
    context.fillRect(0, 0, 100, 100);
  }

  render() {
    return <Canvas style={{
      width: 750,
      height: 750
    }} ref={this.raxCanvasDemo} />;
  }
}

render(<CanvasSample />, document.body, { driver: DriverUniversal });

Keywords

FAQs

Package last updated on 19 Mar 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc