|
| 1 | +/** |
| 2 | + * Copyright (c) 2015-present, Facebook, Inc. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @providesModule takeSnapshot |
| 8 | + * @format |
| 9 | + * @flow |
| 10 | + */ |
| 11 | + |
| 12 | +const ReactNative = require('ReactNative'); |
| 13 | +const UIManager = require('UIManager'); |
| 14 | + |
| 15 | +/** |
| 16 | + * Capture an image of the screen, window or an individual view. The image |
| 17 | + * will be stored in a temporary file that will only exist for as long as the |
| 18 | + * app is running. |
| 19 | + * |
| 20 | + * The `view` argument can be the literal string `window` if you want to |
| 21 | + * capture the entire window, or it can be a reference to a specific |
| 22 | + * React Native component. |
| 23 | + * |
| 24 | + * The `options` argument may include: |
| 25 | + * - width/height (number) - the width and height of the image to capture. |
| 26 | + * - format (string) - either 'png' or 'jpeg'. Defaults to 'png'. |
| 27 | + * - quality (number) - the quality when using jpeg. 0.0 - 1.0 (default). |
| 28 | + * |
| 29 | + * Returns a Promise. |
| 30 | + * @platform ios |
| 31 | + */ |
| 32 | +module.exports = function takeSnapshot( |
| 33 | + view?: 'window' | React$Element<any> | number, |
| 34 | + options?: { |
| 35 | + width?: number, |
| 36 | + height?: number, |
| 37 | + format?: 'png' | 'jpeg', |
| 38 | + quality?: number, |
| 39 | + }, |
| 40 | +): Promise<any> { |
| 41 | + if (typeof view !== 'number' && view !== 'window') { |
| 42 | + view = ReactNative.findNodeHandle(view) || 'window'; |
| 43 | + } |
| 44 | + |
| 45 | + // Call the hidden '__takeSnapshot' method; the main one throws an error to |
| 46 | + // prevent accidental backwards-incompatible usage. |
| 47 | + return UIManager.__takeSnapshot(view, options); |
| 48 | +}; |
0 commit comments