@s77rt/react-native-viewshot
v0.0.2
Published
A React Native module to capture views.
Downloads
11
Readme
@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. |