Procházet zdrojové kódy

Merge pull request #117 from acrazing/master

The types definition for TypeScript
Gaëtan Renaudeau před 6 roky
rodič
revize
919b9b3ccd
No account linked to committer's email address
2 změnil soubory, kde provedl 106 přidání a 0 odebrání
  1. 1
    0
      package.json
  2. 105
    0
      src/index.d.ts

+ 1
- 0
package.json Zobrazit soubor

@@ -3,6 +3,7 @@
3 3
   "version": "2.1.1",
4 4
   "description": "Capture a React Native view to an image",
5 5
   "main": "src/index.js",
6
+  "types": "src/index.d.ts",
6 7
   "keywords": [
7 8
     "react-native",
8 9
     "screenshot",

+ 105
- 0
src/index.d.ts Zobrazit soubor

@@ -0,0 +1,105 @@
1
+/*!
2
+ *
3
+ * Copyright 2017 - acrazing
4
+ *
5
+ * @author acrazing joking.young@gmail.com
6
+ * @since 2017-11-11 16:03:17
7
+ * @version 1.0.0
8
+ * @desc react-native-view-shot.d.ts
9
+ */
10
+
11
+declare module 'react-native-view-shot' {
12
+    import { Component, ReactInstance } from 'react'
13
+
14
+    export interface CaptureOptions {
15
+        /**
16
+         * (number): the width and height of the final image (resized from the View bound. don't provide it if you want
17
+         * the original pixel size).
18
+         */
19
+        width?: number;
20
+        /**
21
+         * @see {CaptureOptions#width}
22
+         */
23
+        height?: number;
24
+        /**
25
+         * either png or jpg or webm (Android). Defaults to png.
26
+         */
27
+        format?: 'jpg' | 'png' | 'webm';
28
+        /**
29
+         * the quality. 0.0 - 1.0 (default). (only available on lossy formats like jpg)
30
+         */
31
+        quality?: number;
32
+        /**
33
+         * the method you want to use to save the snapshot, one of:
34
+         " - tmpfile" (default): save to a temporary file (that will only exist for as long as the app is running).
35
+         " - base64": encode as base64 and returns the raw string. Use only with small images as this may result of
36
+         *   lags (the string is sent over the bridge). N.B. This is not a data uri, use data-uri instead.
37
+         " - data-uri": same as base64 but also includes the Data URI scheme header.
38
+         */
39
+        result?: 'tmpfile' | 'base64' | 'data-uri';
40
+        /**
41
+         * if true and when view is a ScrollView, the "content container" height will be evaluated instead of the
42
+         * container height.
43
+         */
44
+        snapshotContentContainer?: boolean;
45
+    }
46
+
47
+    export interface ViewShotProperties {
48
+        options?: CaptureOptions;
49
+        /**
50
+         * - if not defined (default). the capture is not automatic and you need to use the ref and call capture()
51
+         *   yourself.
52
+         * - "mount". Capture the view once at mount. (It is important to understand image loading won't be waited, in
53
+         *   such case you want to use "none" with viewShotRef.capture() after Image#onLoad.)
54
+         * - "continuous" EXPERIMENTAL, this will capture A LOT of images continuously. For very specific use-cases.
55
+         * - "update" EXPERIMENTAL, this will capture images each time React redraw (on did update). For very specific
56
+         *   use-cases.
57
+         */
58
+        captureMode?: 'mount' | 'continuous' | 'update';
59
+        /**
60
+         * when a captureMode is defined, this callback will be called with the capture result.
61
+         * @param {string} uri
62
+         */
63
+        onCapture?(uri: string): void;
64
+        /**
65
+         * when a captureMode is defined, this callback will be called when a capture fails.
66
+         * @param {Error} error
67
+         */
68
+        onCaptureFailure?(error: Error): void;
69
+    }
70
+
71
+    export default class ViewShot extends Component<ViewShotProperties> {
72
+    }
73
+
74
+    /**
75
+     * lower level imperative API
76
+     *
77
+     * @param {React.ReactInstance} viewRef
78
+     * @param {"react-native-view-shot".CaptureOptions} options
79
+     * @return {Promise<string>} Returns a Promise of the image URI.
80
+     */
81
+    export function captureRef(viewRef: ReactInstance, options?: CaptureOptions): Promise<string>
82
+
83
+    /**
84
+     * This method release a previously captured uri. For tmpfile it will clean them out, for other result types it
85
+     * just won't do anything.
86
+     *
87
+     * NB: the tmpfile captures are automatically cleaned out after the app closes, so you might not have to worry
88
+     *  about this unless advanced usecases. The ViewShot component will use it each time you capture more than once
89
+     * (useful for continuous capture to not leak files).
90
+     * @param {string} uri
91
+     */
92
+    export function releaseCapture(uri: string): void
93
+
94
+    /**
95
+     * This method will capture the contents of the currently displayed screen as a native hardware screenshot. It does
96
+     * not require a ref input, as it does not work at the view level. This means that ScrollViews will not be captured
97
+     * in their entirety - only the portions currently visible to the user.
98
+     *
99
+     * Returns a Promise of the image URI.
100
+     *
101
+     * @param {"react-native-view-shot".CaptureOptions} options
102
+     * @return {Promise<string>}
103
+     */
104
+    export function captureScreen(options?: CaptureOptions): Promise<string>
105
+}