You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+10-24Lines changed: 10 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,38 +34,24 @@ Returns a Promise of the image URI.
34
34
35
35
-**`view`** is a reference to a React Native component.
36
36
-**`options`** may include:
37
-
-**`width`** / **`height`***(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).
38
-
-**`format`***(string)*: either `png` or `jpg`/`jpeg` or `webm` (Android). Defaults to `png`.
39
-
-**`quality`***(number)*: the quality. 0.0 - 1.0 (default). (only available on lossy formats like jpeg)
40
-
-**`result`***(string)*, the method you want to use to save the snapshot, one of:
37
+
-**`width`** / **`height`***(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).
38
+
-**`format`***(string)*: either `png` or `jpg`/`jpeg` or `webm` (Android). Defaults to `png`.
39
+
-**`quality`***(number)*: the quality. 0.0 - 1.0 (default). (only available on lossy formats like jpeg)
40
+
-**`result`***(string)*, the method you want to use to save the snapshot, one of:
41
41
-`"file"` (default): save to a temporary file *(that will only exist for as long as the app is running)*.
42
42
-`"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*.
43
43
-`"data-uri"`: same as `base64` but also includes the [Data URI scheme](https://en.wikipedia.org/wiki/Data_URI_scheme) header.
44
-
-**`path`***(string)*: The absolute path where the file get generated. **Read below before using it!**
45
44
-**`snapshotContentContainer`***(bool)*: if true and when view is a ScrollView, the "content container" height will be evaluated instead of the container height.
46
45
47
-
### `path` option and `dirs` constants
46
+
### DEPRECATED `path` option and `dirs` constants
48
47
49
-
**IMPORTANT: We might actually drop the path feature because of its complexity in the current codebase (and bugs that are not fixed), please consider using react-native-view-shot with https://github.com/itinance/react-native-fs to solve this.**
48
+
> A feature used to allow to set an arbitrary file path. This has become tricky to maintain because all the edge cases and use-cases of file management so we have decided to drop it, making this library focusing more on solving snapshotting and not file system.
50
49
51
-
By default, takeSnapshot will export in a temporary folder and the snapshot file will be deleted as soon as the app leaves.
52
-
But if you use the `path` option, you make the snapshot file more permanent and at a specific file location. it is up to you to manage the image file lifecycle, the library won't clean it for you (which might result of leaking files on user's phone if you are not careful). There is also no guarantee the file will be successfully saved: you can reach permissions problem, this also is platform specific.
50
+
To migrate from this old feature, you have a few solutions:
53
51
54
-
If you still want to do this, we expose a few somewhat universal "constants" to ease the work.
- If you want to save the snapshotted image result to the CameraRoll, just use https://facebook.github.io/react-native/docs/cameraroll.html#savetocameraroll
53
+
- If you want to save it to an arbitrary file path, use something like https://github.com/itinance/react-native-fs
54
+
- For any more advanced needs, you can write your own (or find another) native module that would solve your use-case.
Copy file name to clipboardExpand all lines: index.js
+16-4Lines changed: 16 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ export const dirs = {
14
14
DCIMDir: RNViewShot.DCIMDir,
15
15
DownloadDir: RNViewShot.DownloadDir,
16
16
RingtoneDir: RNViewShot.RingtoneDir,
17
-
SDCardDir: RNViewShot.SDCardDir,
17
+
SDCardDir: RNViewShot.SDCardDir
18
18
};
19
19
20
20
exportfunctiontakeSnapshot(
@@ -25,13 +25,25 @@ export function takeSnapshot(
25
25
path?: string,
26
26
format?: "png"|"jpg"|"jpeg"|"webm",
27
27
quality?: number,
28
-
result?: "file"|"base64"|"data-uri",
29
-
snapshotContentContainer?: bool
28
+
result?: "tmpfile"|"file"|"base64"|"data-uri",
29
+
snapshotContentContainer?: boolean
30
30
}={}
31
31
): Promise<string>{
32
+
if(options.result==="file"){
33
+
console.warn(
34
+
"react-native-view-shot: result='file' is deprecated, has been renamed to 'tmpfile' and no longer support any 'path' option. See README for more information"
35
+
);
36
+
}elseif("path"inoptions){
37
+
console.warn(
38
+
"react-native-view-shot: path option is deprecated. See README for more information"
39
+
);
40
+
}
32
41
if(typeofview!=="number"){
33
42
constnode=findNodeHandle(view);
34
-
if(!node)returnPromise.reject(newError("findNodeHandle failed to resolve view="+String(view)));
43
+
if(!node)
44
+
returnPromise.reject(
45
+
newError("findNodeHandle failed to resolve view="+String(view))
reject(RCTErrorUnspecified, @"The view cannot be captured. drawViewHierarchyInRect was not successful. This is a potential technical or security limitation.", nil);
0 commit comments