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
-**`view`** is a reference to a React Native component.
36
36
-**`options`** may include:
37
-
-**`width`** / **`height`***(number)*: the width and height of the image to capture.
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
38
-**`format`***(string)*: either `png` or `jpg`/`jpeg` or `webm` (Android). Defaults to `png`.
39
39
-**`quality`***(number)*: the quality. 0.0 - 1.0 (default). (only available on lossy formats like jpeg)
40
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
-
-**`filename`***(string)*: the name of the generated file if any (Android only). Defaults to `ReactNative_snapshot_image_${timestamp}`.
45
-
-**`snapshotContentContainer`***(bool)*: if true and when view is a ScrollView, the "content container" height will be evaluated instead of the container height. (Android only)
44
+
-**`path`***(string)*: The absolute path where the file get generated. See *`dirs` constants* for more information.
45
+
-**`snapshotContentContainer`***(bool)*: if true and when view is a ScrollView, the "content container" height will be evaluated instead of the container height.
46
+
47
+
### `dirs` constants
48
+
49
+
By default, takeSnapshot will export in a temporary folder and the snapshot file will be deleted as soon as the app leaves. If you use the `path` option, you make the snapshot file more permanent and at a specific file location. To make file location more 'universal', the library exports some classic directory constants:
1. Only supported by wrapping a `<View collapsable={false}>` parent and snapshotting it.
79
+
2. It returns an empty image (not a failure Promise).
80
+
3. Component itself lacks platform support.
46
81
47
82
## Caveats
48
83
49
84
Snapshots are not guaranteed to be pixel perfect. It also depends on the platform. Here is some difference we have noticed and how to workaround.
50
85
51
-
- Support of special components like Video / GL views remains untested.
86
+
- Support of special components like Video / GL views is not guaranteed to work. In case of failure, the `takeSnapshot` promise gets rejected (the library won't crash).
52
87
- It's preferable to **use a background color on the view you rasterize** to avoid transparent pixels and potential weirdness that some border appear around texts.
53
88
54
89
### specific to Android implementation
55
90
56
-
- you need to make sure `collapsable` is set to `false` if you want to snapshot a **View**. Otherwise that view won't reflect any UI View. ([found by @gaguirre](https://github.com/gre/react-native-view-shot/issues/7#issuecomment-245302844))
57
-
- if you want to share out the screenshoted file, you will have to copy it somewhere first so it's accessible to an Intent, see comment: https://github.com/gre/react-native-view-shot/issues/11#issuecomment-251080804 .
58
-
- if you implement a third party library and want to get back a File, you must first resolve the `Uri`. the `file` result returns an `Uri` so it's consistent with iOS and you can give it to `Image.getSize` for instance.
91
+
- you need to make sure `collapsable` is set to `false` if you want to snapshot a **View**. Some content might even need to be wrapped into such `<View collapsable={false}>` to actually make them snapshotable! Otherwise that view won't reflect any UI View. ([found by @gaguirre](https://github.com/gre/react-native-view-shot/issues/7#issuecomment-245302844))
92
+
- if you implement a third party library and want to get back a File, you must first resolve the `Uri`. (the `file` result returns an `Uri` so it's consistent with iOS and can be given to APIs like `Image.getSize`)
59
93
60
94
## Getting started
61
95
@@ -100,7 +134,6 @@ react-native link react-native-view-shot
100
134
3. In Visual Studio, in the solution explorer, right click on your Application project then select `Add` ➜ `Reference`
101
135
4. Under the projects tab select `RNViewShot` (UWP) or `RNViewShot.Net46` (WPF)
102
136
103
-
104
137
## Thanks
105
138
106
139
- To initial iOS work done by @jsierles in https://github.com/jsierles/react-native-view-snapshot
0 commit comments