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.0.0
  • npm
  • Socket score

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

npm 描述: 画布组件.

在 Weex 上依赖 gcanvas 在支付宝小程序中依赖 canvas 在 Web 和 Weex 中可以通过 ref 获取画布实例,在小程序中需要通过 createCanvasContext 和画布的 id 获取 canvas 上下文

安装

$ npm install rax-canvas --save

引用

import Canvas from 'rax-canvas';

属性

注: 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代表微信小程序

方法

获取到画布实例后,可以使用实例上的方法。

示例

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 });

注意

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

Keywords

FAQs

Package last updated on 16 Dec 2019

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