@s77rt/react-native-viewshot

0.0.2 • Public • Published

@s77rt/react-native-viewshot

A React Native module to capture views.

Installation

npm install @s77rt/react-native-viewshot

Usage

Attach ref to View and pass collapsable={false}

<View
  ref={viewRef}
  collapsable={false} // Important to ensure existence in native view hierarchy
/>

Use Viewshot

import { findNodeHandle } from "react-native";
import Viewshot from "@s77rt/react-native-viewshot";

const captureView = useCallback(() => {
  const nodeHandle = findNodeHandle(viewRef.current);
  if (!nodeHandle) {
    return;
  }

  Viewshot.capture(nodeHandle)
    .then((uri) => {
      console.log(uri);
    })
    .catch((error) => {
      console.error(error);
    });
}, []);

Methods

Name Arguments Description
capture nodeHandle: number Capture a view given its handle/reactTag. Returns a Promise<string> with the file uri. Note: File is saved as PNG.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @s77rt/react-native-viewshot

Weekly Downloads

3

Version

0.0.2

License

MIT

Unpacked Size

11.6 kB

Total Files

12

Last publish

Collaborators

  • s77rt