123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- /*!
- *
- * Copyright 2017 - acrazing
- *
- * @author acrazing joking.young@gmail.com
- * @since 2017-11-11 16:03:17
- * @version 1.0.0
- * @desc react-native-view-shot.d.ts
- */
-
- declare module 'react-native-view-shot' {
- import { Component, ReactInstance } from 'react'
- import { StyleObj } from 'react-native/Libraries/StyleSheet/StyleSheetTypes'
-
- export interface CaptureOptions {
- /**
- * (number): the width and height of the final image (resized from the View bound. don't provide it if you want
- * the original pixel size).
- */
- width?: number;
- /**
- * @see {CaptureOptions#width}
- */
- height?: number;
- /**
- * either png or jpg or webm (Android). Defaults to png. raw is a ARGB array of image pixels.
- */
- format?: 'jpg' | 'png' | 'webm' | 'raw';
- /**
- * the quality. 0.0 - 1.0 (default). (only available on lossy formats like jpg)
- */
- quality?: number;
- /**
- * the method you want to use to save the snapshot, one of:
- " - tmpfile" (default): save to a temporary file (that will only exist for as long as the app is running).
- " - base64": encode as base64 and returns the raw string. Use only with small images as this may result of
- * lags (the string is sent over the bridge). N.B. This is not a data uri, use data-uri instead.
- " - data-uri": same as base64 but also includes the Data URI scheme header.
- " - zip-base64: compress data with zip deflate algorithm and than convert to base64 and return as a raw string."
- */
- result?: 'tmpfile' | 'base64' | 'data-uri' | 'zip-base64';
- /**
- * if true and when view is a ScrollView, the "content container" height will be evaluated instead of the
- * container height.
- */
- snapshotContentContainer?: boolean;
- }
-
- export interface ViewShotProperties {
- options?: CaptureOptions;
- /**
- * - if not defined (default). the capture is not automatic and you need to use the ref and call capture()
- * yourself.
- * - "mount". Capture the view once at mount. (It is important to understand image loading won't be waited, in
- * such case you want to use "none" with viewShotRef.capture() after Image#onLoad.)
- * - "continuous" EXPERIMENTAL, this will capture A LOT of images continuously. For very specific use-cases.
- * - "update" EXPERIMENTAL, this will capture images each time React redraw (on did update). For very specific
- * use-cases.
- */
- captureMode?: 'mount' | 'continuous' | 'update';
- /**
- * when a captureMode is defined, this callback will be called with the capture result.
- * @param {string} uri
- */
- onCapture?(uri: string): void;
- /**
- * when a captureMode is defined, this callback will be called when a capture fails.
- * @param {Error} error
- */
- onCaptureFailure?(error: Error): void;
- /**
- * style prop as StyleObj
- */
- style?: StyleObj;
- }
-
- export default class ViewShot extends Component<ViewShotProperties> {
- }
-
- /**
- * lower level imperative API
- *
- * @param {React.ReactInstance} viewRef
- * @param {"react-native-view-shot".CaptureOptions} options
- * @return {Promise<string>} Returns a Promise of the image URI.
- */
- export function captureRef(viewRef: ReactInstance, options?: CaptureOptions): Promise<string>
-
- /**
- * This method release a previously captured uri. For tmpfile it will clean them out, for other result types it
- * just won't do anything.
- *
- * NB: the tmpfile captures are automatically cleaned out after the app closes, so you might not have to worry
- * about this unless advanced usecases. The ViewShot component will use it each time you capture more than once
- * (useful for continuous capture to not leak files).
- * @param {string} uri
- */
- export function releaseCapture(uri: string): void
-
- /**
- * This method will capture the contents of the currently displayed screen as a native hardware screenshot. It does
- * not require a ref input, as it does not work at the view level. This means that ScrollViews will not be captured
- * in their entirety - only the portions currently visible to the user.
- *
- * Returns a Promise of the image URI.
- *
- * @param {"react-native-view-shot".CaptureOptions} options
- * @return {Promise<string>}
- */
- export function captureScreen(options?: CaptureOptions): Promise<string>
- }
|