0.0.2 • Published 10 months ago

@s77rt/react-native-viewshot v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

@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

NameArgumentsDescription
capturenodeHandle: numberCapture a view given its handle/reactTag. Returns a Promise<string> with the file uri. Note: File is saved as PNG.

License

MIT

0.0.2

10 months ago

0.0.1

10 months ago