index.js 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //@flow
  2. import { NativeModules, findNodeHandle } from "react-native";
  3. const { RNViewShot } = NativeModules;
  4. export const dirs = {
  5. // cross platform
  6. CacheDir: RNViewShot.CacheDir,
  7. DocumentDir: RNViewShot.DocumentDir,
  8. MainBundleDir: RNViewShot.MainBundleDir,
  9. MovieDir: RNViewShot.MovieDir,
  10. MusicDir: RNViewShot.MusicDir,
  11. PictureDir: RNViewShot.PictureDir,
  12. // only Android
  13. DCIMDir: RNViewShot.DCIMDir,
  14. DownloadDir: RNViewShot.DownloadDir,
  15. RingtoneDir: RNViewShot.RingtoneDir,
  16. SDCardDir: RNViewShot.SDCardDir,
  17. };
  18. export function takeSnapshot(
  19. view: number | ReactElement<any>,
  20. options?: {
  21. width?: number,
  22. height?: number,
  23. path?: string,
  24. format?: "png" | "jpg" | "jpeg" | "webm",
  25. quality?: number,
  26. result?: "file" | "base64" | "data-uri",
  27. snapshotContentContainer?: bool
  28. } = {}
  29. ): Promise<string> {
  30. if (typeof view !== "number") {
  31. const node = findNodeHandle(view);
  32. if (!node) return Promise.reject(new Error("findNodeHandle failed to resolve view="+String(view)));
  33. view = node;
  34. }
  35. return RNViewShot.takeSnapshot(view, options);
  36. }
  37. export default { takeSnapshot, dirs };