Browse Source

introduced RAW image format and ZIP-base64 result packaging algorithm

Oleksandr Kucherenko 5 years ago
parent
commit
f8af243189
2 changed files with 12 additions and 9 deletions
  1. 4
    3
      src/index.d.ts
  2. 8
    6
      src/index.js

+ 4
- 3
src/index.d.ts View File

@@ -23,9 +23,9 @@ declare module 'react-native-view-shot' {
23 23
          */
24 24
         height?: number;
25 25
         /**
26
-         * either png or jpg or webm (Android). Defaults to png.
26
+         * either png or jpg or webm (Android). Defaults to png. raw is a ARGB array of image pixels.
27 27
          */
28
-        format?: 'jpg' | 'png' | 'webm';
28
+        format?: 'jpg' | 'png' | 'webm' | 'raw';
29 29
         /**
30 30
          * the quality. 0.0 - 1.0 (default). (only available on lossy formats like jpg)
31 31
          */
@@ -36,8 +36,9 @@ declare module 'react-native-view-shot' {
36 36
          " - base64": encode as base64 and returns the raw string. Use only with small images as this may result of
37 37
          *   lags (the string is sent over the bridge). N.B. This is not a data uri, use data-uri instead.
38 38
          " - data-uri": same as base64 but also includes the Data URI scheme header.
39
+         " - zip-base64: compress data with zip deflate algorithm and than convert to base64 and return as a raw string."
39 40
          */
40
-        result?: 'tmpfile' | 'base64' | 'data-uri';
41
+        result?: 'tmpfile' | 'base64' | 'data-uri' | 'zip-base64';
41 42
         /**
42 43
          * if true and when view is a ScrollView, the "content container" height will be evaluated instead of the
43 44
          * container height.

+ 8
- 6
src/index.js View File

@@ -8,9 +8,9 @@ const neverEndingPromise = new Promise(() => {});
8 8
 type Options = {
9 9
   width?: number,
10 10
   height?: number,
11
-  format: "png" | "jpg" | "webm",
11
+  format: "png" | "jpg" | "webm" | "raw",
12 12
   quality: number,
13
-  result: "tmpfile" | "base64" | "data-uri",
13
+  result: "tmpfile" | "base64" | "data-uri" | "zip-base64",
14 14
   snapshotContentContainer: boolean
15 15
 };
16 16
 
@@ -21,10 +21,12 @@ if (!RNViewShot) {
21 21
 }
22 22
 
23 23
 const acceptedFormats = ["png", "jpg"].concat(
24
-  Platform.OS === "android" ? ["webm"] : []
24
+  Platform.OS === "android" ? ["webm", "raw"] : []
25 25
 );
26 26
 
27
-const acceptedResults = ["tmpfile", "base64", "data-uri"];
27
+const acceptedResults = ["tmpfile", "base64", "data-uri"].concat(
28
+  Platform.OS === "android" ? ["zip-base64"] : []
29
+);
28 30
 
29 31
 const defaultOptions = {
30 32
   format: "png",
@@ -70,13 +72,13 @@ function validateOptions(
70 72
   if (acceptedFormats.indexOf(options.format) === -1) {
71 73
     options.format = defaultOptions.format;
72 74
     errors.push(
73
-      "option format is not in valid formats: " + acceptedFormats.join(" | ")
75
+      "option format '" + options.format + "' is not in valid formats: " + acceptedFormats.join(" | ")
74 76
     );
75 77
   }
76 78
   if (acceptedResults.indexOf(options.result) === -1) {
77 79
     options.result = defaultOptions.result;
78 80
     errors.push(
79
-      "option result is not in valid formats: " + acceptedResults.join(" | ")
81
+      "option result '" + options.result  + "' is not in valid formats: " + acceptedResults.join(" | ")
80 82
     );
81 83
   }
82 84
   return { options, errors };