npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-native-canvas-hash

v1.1.0

Published

High-performance native Android canvas component for React Native with drawing, erasing, undo/redo support

Readme

react-native-canvas-hash

Note this is only for android

High-performance native Android canvas component for React Native with drawing, erasing, undo/redo support.

Features

  • Native Android Performance - Built with Kotlin for optimal performance
  • Drawing - Smooth pen drawing with customizable color and size
  • Eraser - Erase drawings with customizable eraser size
  • Undo/Redo - Full undo/redo support
  • Hand Mode - Enable scrolling when hand tool is active
  • Base64 Export - Export drawings as base64 images
  • Path Counting - Get path counts for undo/redo button states

Installation

npm install react-native-canvas-hash
# or
yarn add react-native-canvas-hash

Android Setup

  1. Add the package to settings.gradle (in your project's android folder):
include ':react-native-canvas-hash'
project(':react-native-canvas-hash').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-canvas-hash/android')
  1. Add the dependency to your app's build.gradle (usually android/app/build.gradle):
dependencies {
    // ... other dependencies
    implementation project(':react-native-canvas-hash')
}
  1. Add the package to your MainApplication.java (or MainApplication.kt if using Kotlin):

For Java:

import com.hash.canvas.CanvasPackage

public class MainApplication extends Application implements ReactApplication {
  // ...
  
  @Override
  protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
      new MainReactPackage(),
      add(CanvasPackage()) // Add this line
    );
  }
}

For Kotlin:

import com.hash.canvas.CanvasPackage

class MainApplication : Application(), ReactApplication {
  // ...
  
  override fun getPackages(): List<ReactPackage> {
    return listOf(
      MainReactPackage(),
      CanvasPackage() // Add this line
    )
  }
}
  1. Sync Gradle files (in Android Studio: File → Sync Project with Gradle Files) and rebuild.

Usage

import React, { useRef } from 'react';
import { View, StyleSheet } from 'react-native';
import CanvasView, { CanvasViewRef } from 'react-native-canvas-hash';

const App = () => {
  const canvasRef = useRef<CanvasViewRef>(null);

  const handleUndo = async () => {
    await canvasRef.current?.undo();
  };

  const handleRedo = async () => {
    await canvasRef.current?.redo();
  };

  const handleClear = async () => {
    await canvasRef.current?.clear();
  };

  const handleSave = async () => {
    const base64 = await canvasRef.current?.readSignature();
    console.log('Drawing saved:', base64);
  };

  return (
    <View style={styles.container}>
      <CanvasView
        ref={canvasRef}
        style={styles.canvas}
        penColor="rgba(255, 0, 0, 1)"
        penSize={3}
        eraserSize={20}
        isEraserMode={false}
        isHandMode={false}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  canvas: {
    flex: 1,
    backgroundColor: 'transparent',
  },
});

Props

CanvasView Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | penColor | string | "rgba(255, 0, 0, 1)" | Pen color in rgba format | | penSize | number | 2 | Pen stroke width | | eraserSize | number | 20 | Eraser stroke width | | isEraserMode | boolean | false | Enable eraser mode | | isHandMode | boolean | false | Enable hand mode (allows scrolling) |

Methods

CanvasViewRef Methods

All methods return Promises and should be awaited.

  • undo() - Undo last drawing action
  • redo() - Redo last undone action
  • clear() - Clear all drawings
  • readSignature() - Get base64 image string (data URI format)
  • getData() - Get base64 image string (raw base64)
  • getPathCount() - Get current path count (for undo button state)
  • getUndonePathCount() - Get undone path count (for redo button state)

Example: Full Drawing App

import React, { useRef, useState } from 'react';
import { View, StyleSheet, TouchableOpacity, Text } from 'react-native';
import CanvasView, { CanvasViewRef } from 'react-native-canvas-hash';

const DrawingApp = () => {
  const canvasRef = useRef<CanvasViewRef>(null);
  const [isEraser, setIsEraser] = useState(false);
  const [canUndo, setCanUndo] = useState(false);
  const [canRedo, setCanRedo] = useState(false);

  // Check undo/redo state periodically
  React.useEffect(() => {
    const interval = setInterval(async () => {
      const pathCount = await canvasRef.current?.getPathCount() || 0;
      const undoneCount = await canvasRef.current?.getUndonePathCount() || 0;
      setCanUndo(pathCount > 0);
      setCanRedo(undoneCount > 0);
    }, 100);
    return () => clearInterval(interval);
  }, []);

  return (
    <View style={styles.container}>
      <CanvasView
        ref={canvasRef}
        style={styles.canvas}
        penColor="rgba(255, 0, 0, 1)"
        penSize={3}
        eraserSize={20}
        isEraserMode={isEraser}
        isHandMode={false}
      />
      <View style={styles.toolbar}>
        <TouchableOpacity
          style={[styles.button, isEraser && styles.buttonActive]}
          onPress={() => setIsEraser(!isEraser)}
        >
          <Text>Eraser</Text>
        </TouchableOpacity>
        <TouchableOpacity
          style={[styles.button, !canUndo && styles.buttonDisabled]}
          onPress={() => canvasRef.current?.undo()}
          disabled={!canUndo}
        >
          <Text>Undo</Text>
        </TouchableOpacity>
        <TouchableOpacity
          style={[styles.button, !canRedo && styles.buttonDisabled]}
          onPress={() => canvasRef.current?.redo()}
          disabled={!canRedo}
        >
          <Text>Redo</Text>
        </TouchableOpacity>
        <TouchableOpacity
          style={styles.button}
          onPress={() => canvasRef.current?.clear()}
        >
          <Text>Clear</Text>
        </TouchableOpacity>
      </View>
    </View>
  );
};

License

MIT

Author

Hamid