Quellcode durchsuchen

add example for blur and adapt some flowtype

Gaëtan Renaudeau vor 4 Jahren
Ursprung
Commit
78049bcff4
Es ist kein Benutzerkonto mit dieser Commiter-Email verbunden

+ 1
- 0
example/.gitignore Datei anzeigen

4
 
4
 
5
 # Xcode
5
 # Xcode
6
 #
6
 #
7
+xcshareddata/
7
 build/
8
 build/
8
 *.pbxuser
9
 *.pbxuser
9
 !default.pbxuser
10
 !default.pbxuser

+ 6
- 0
example/ios/Podfile.lock Datei anzeigen

182
     - React-cxxreact (= 0.61.5)
182
     - React-cxxreact (= 0.61.5)
183
     - React-jsi (= 0.61.5)
183
     - React-jsi (= 0.61.5)
184
   - React-jsinspector (0.61.5)
184
   - React-jsinspector (0.61.5)
185
+  - react-native-blur (0.8.0):
186
+    - React
185
   - react-native-maps (0.26.1):
187
   - react-native-maps (0.26.1):
186
     - React
188
     - React
187
   - react-native-safe-area-context (0.6.2):
189
   - react-native-safe-area-context (0.6.2):
266
   - React-jsi (from `../node_modules/react-native/ReactCommon/jsi`)
268
   - React-jsi (from `../node_modules/react-native/ReactCommon/jsi`)
267
   - React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
269
   - React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
268
   - React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
270
   - React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
271
+  - "react-native-blur (from `../node_modules/@react-native-community/blur`)"
269
   - react-native-maps (from `../node_modules/react-native-maps`)
272
   - react-native-maps (from `../node_modules/react-native-maps`)
270
   - react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
273
   - react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
271
   - "react-native-slider (from `../node_modules/@react-native-community/slider`)"
274
   - "react-native-slider (from `../node_modules/@react-native-community/slider`)"
325
     :path: "../node_modules/react-native/ReactCommon/jsiexecutor"
328
     :path: "../node_modules/react-native/ReactCommon/jsiexecutor"
326
   React-jsinspector:
329
   React-jsinspector:
327
     :path: "../node_modules/react-native/ReactCommon/jsinspector"
330
     :path: "../node_modules/react-native/ReactCommon/jsinspector"
331
+  react-native-blur:
332
+    :path: "../node_modules/@react-native-community/blur"
328
   react-native-maps:
333
   react-native-maps:
329
     :path: "../node_modules/react-native-maps"
334
     :path: "../node_modules/react-native-maps"
330
   react-native-safe-area-context:
335
   react-native-safe-area-context:
390
   React-jsi: cb2cd74d7ccf4cffb071a46833613edc79cdf8f7
395
   React-jsi: cb2cd74d7ccf4cffb071a46833613edc79cdf8f7
391
   React-jsiexecutor: d5525f9ed5f782fdbacb64b9b01a43a9323d2386
396
   React-jsiexecutor: d5525f9ed5f782fdbacb64b9b01a43a9323d2386
392
   React-jsinspector: fa0ecc501688c3c4c34f28834a76302233e29dc0
397
   React-jsinspector: fa0ecc501688c3c4c34f28834a76302233e29dc0
398
+  react-native-blur: cad4d93b364f91e7b7931b3fa935455487e5c33c
393
   react-native-maps: 6e499eee4eabf422ba8b6f94e993cc768bf35153
399
   react-native-maps: 6e499eee4eabf422ba8b6f94e993cc768bf35153
394
   react-native-safe-area-context: 25260c5d0b9c53fd7aa88e569e2edae72af1f6a3
400
   react-native-safe-area-context: 25260c5d0b9c53fd7aa88e569e2edae72af1f6a3
395
   react-native-slider: 3a1cfd00c9c31068251b536822f7192e8d1d6b6f
401
   react-native-slider: 3a1cfd00c9c31068251b536822f7192e8d1d6b6f

+ 1
- 0
example/package.json Datei anzeigen

8
   },
8
   },
9
   "dependencies": {
9
   "dependencies": {
10
     "@react-native-community/art": "^1.1.2",
10
     "@react-native-community/art": "^1.1.2",
11
+    "@react-native-community/blur": "^3.4.1",
11
     "@react-native-community/masked-view": "^0.1.6",
12
     "@react-native-community/masked-view": "^0.1.6",
12
     "@react-native-community/slider": "^2.0.8",
13
     "@react-native-community/slider": "^2.0.8",
13
     "gl-react": "2",
14
     "gl-react": "2",

+ 1
- 1
example/src/ART.js Datei anzeigen

41
 
41
 
42
       <Desc desc="ART overlapping test" />
42
       <Desc desc="ART overlapping test" />
43
 
43
 
44
-      <Image source={source} style={dimension} />
44
+      <Image fadeDuration={0} source={source} style={dimension} />
45
     </SafeAreaView>
45
     </SafeAreaView>
46
   );
46
   );
47
 };
47
 };

+ 4
- 0
example/src/App.js Datei anzeigen

7
 // To add a screen, import it and add it in screens
7
 // To add a screen, import it and add it in screens
8
 
8
 
9
 import FullScreen from './Full';
9
 import FullScreen from './Full';
10
+import BlurScreen from './Blur';
10
 import ViewshootScreen from './Viewshoot';
11
 import ViewshootScreen from './Viewshoot';
11
 import TransparencyScreen from './Transparency';
12
 import TransparencyScreen from './Transparency';
12
 import VideoScreen from './Video';
13
 import VideoScreen from './Video';
36
   ART: {
37
   ART: {
37
     screen: ARTScreen,
38
     screen: ARTScreen,
38
   },
39
   },
40
+  Blur: {
41
+    screen: BlurScreen,
42
+  },
39
   FS: {
43
   FS: {
40
     screen: FSScreen,
44
     screen: FSScreen,
41
   },
45
   },

+ 45
- 0
example/src/Blur.js Datei anzeigen

1
+//@flow
2
+import React, { useState, useCallback, useRef, useEffect } from 'react';
3
+import { SafeAreaView, View, Image, findNodeHandle } from 'react-native';
4
+import { BlurView } from '@react-native-community/blur';
5
+import ViewShot from 'react-native-view-shot';
6
+import Desc from './Desc';
7
+
8
+const dimension = { width: 300, height: 300 };
9
+
10
+const SvgUriExample = () => {
11
+  const [source, setSource] = useState(null);
12
+  const [viewHandle, setRefHandle] = useState(null);
13
+  const onCapture = useCallback(uri => setSource({ uri }), []);
14
+  const viewRef = useRef();
15
+  const ref = useRef();
16
+  useEffect(() => {
17
+    const timeout = setTimeout(() => {
18
+      if (ref.current) ref.current.capture();
19
+    }, 1000);
20
+    return () => clearTimeout(timeout);
21
+  }, []);
22
+  const absoluteDimension = { ...dimension, position: 'absolute' };
23
+  return (
24
+    <SafeAreaView>
25
+      <ViewShot ref={ref} captureMode="mount" onCapture={onCapture} style={dimension}>
26
+        <Image
27
+          source={require('./bg.jpg')}
28
+          style={absoluteDimension}
29
+          ref={ref => setRefHandle(findNodeHandle(ref))}
30
+        />
31
+        <BlurView blurType="light" blurAmount={10} style={absoluteDimension} viewRef={viewHandle} />
32
+      </ViewShot>
33
+
34
+      <Desc desc="above is a blurred SVG view and below is a screenshot of it" />
35
+
36
+      <Image fadeDuration={0} source={source} style={dimension} />
37
+    </SafeAreaView>
38
+  );
39
+};
40
+
41
+SvgUriExample.navigationOptions = {
42
+  title: 'react-native-community/blur',
43
+};
44
+
45
+export default SvgUriExample;

+ 1
- 1
example/src/Canvas.js Datei anzeigen

34
         <CanvasRendering onDrawn={onCapture} />
34
         <CanvasRendering onDrawn={onCapture} />
35
       </ViewShot>
35
       </ViewShot>
36
 
36
 
37
-      <Image source={source} style={dimension} />
37
+      <Image fadeDuration={0} source={source} style={dimension} />
38
     </SafeAreaView>
38
     </SafeAreaView>
39
   );
39
   );
40
 };
40
 };

+ 1
- 1
example/src/FS.js Datei anzeigen

27
 
27
 
28
       <Desc desc="FS to get the image from captured file" />
28
       <Desc desc="FS to get the image from captured file" />
29
 
29
 
30
-      <Image source={source} style={dimension} />
30
+      <Image fadeDuration={0} source={source} style={dimension} />
31
     </SafeAreaView>
31
     </SafeAreaView>
32
   );
32
   );
33
 };
33
 };

+ 1
- 1
example/src/GLReactV2.js Datei anzeigen

38
 
38
 
39
       <Desc desc="above is a gl-react surface and below is a capture of it" />
39
       <Desc desc="above is a gl-react surface and below is a capture of it" />
40
 
40
 
41
-      <Image source={source} style={dimension} />
41
+      <Image fadeDuration={0} source={source} style={dimension} />
42
     </SafeAreaView>
42
     </SafeAreaView>
43
   );
43
   );
44
 };
44
 };

+ 1
- 1
example/src/MapView.js Datei anzeigen

26
 
26
 
27
       <Desc desc="above is a map view and below is a continuous screenshot of it" />
27
       <Desc desc="above is a map view and below is a continuous screenshot of it" />
28
 
28
 
29
-      <Image source={source} style={dimension} />
29
+      <Image fadeDuration={0} source={source} style={dimension} />
30
     </SafeAreaView>
30
     </SafeAreaView>
31
   );
31
   );
32
 };
32
 };

+ 1
- 1
example/src/Modal.js Datei anzeigen

55
             screenshot Modal as part of a captureScreen."
55
             screenshot Modal as part of a captureScreen."
56
           />
56
           />
57
           <Btn onPress={onOpenModal} label="Open Modal" />
57
           <Btn onPress={onOpenModal} label="Open Modal" />
58
-          <Image source={source} style={styles.preview} resizeMode="contain" />
58
+          <Image fadeDuration={0} source={source} style={styles.preview} resizeMode="contain" />
59
         </View>
59
         </View>
60
       </SafeAreaView>
60
       </SafeAreaView>
61
 
61
 

+ 1
- 1
example/src/Offscreen.js Datei anzeigen

19
   return (
19
   return (
20
     <SafeAreaView>
20
     <SafeAreaView>
21
       <Desc desc="We have rendered this SVG as image offscreen:" />
21
       <Desc desc="We have rendered this SVG as image offscreen:" />
22
-      <Image source={source} style={{ width, height }} />
22
+      <Image fadeDuration={0} source={source} style={{ width, height }} />
23
 
23
 
24
       <OffscreenViewShot
24
       <OffscreenViewShot
25
         captureMode="continuous"
25
         captureMode="continuous"

+ 1
- 1
example/src/SVGUri.js Datei anzeigen

18
 
18
 
19
       <Desc desc="above is an SVG view and below is a continuous screenshot of it" />
19
       <Desc desc="above is an SVG view and below is a continuous screenshot of it" />
20
 
20
 
21
-      <Image source={source} style={dimension} />
21
+      <Image fadeDuration={0} source={source} style={dimension} />
22
     </SafeAreaView>
22
     </SafeAreaView>
23
   );
23
   );
24
 };
24
 };

+ 1
- 1
example/src/Transparency.js Datei anzeigen

39
           justifyContent: 'center',
39
           justifyContent: 'center',
40
         }}
40
         }}
41
       >
41
       >
42
-        <Image source={source} style={{ width: 100, height: 100 }} />
42
+        <Image fadeDuration={0} source={source} style={{ width: 100, height: 100 }} />
43
       </View>
43
       </View>
44
     </View>
44
     </View>
45
   );
45
   );

+ 1
- 1
example/src/Video.js Datei anzeigen

18
 
18
 
19
       <Desc desc="above is a video and below is a continuous screenshot of it" />
19
       <Desc desc="above is a video and below is a continuous screenshot of it" />
20
 
20
 
21
-      <Image source={source} style={dimension} />
21
+      <Image fadeDuration={0} source={source} style={dimension} />
22
     </SafeAreaView>
22
     </SafeAreaView>
23
   );
23
   );
24
 };
24
 };

+ 1
- 1
example/src/WebView.js Datei anzeigen

22
 
22
 
23
       <Desc desc="above is a webview and below is a continuous screenshot of it" />
23
       <Desc desc="above is a webview and below is a continuous screenshot of it" />
24
 
24
 
25
-      <Image source={source} style={dimension} />
25
+      <Image fadeDuration={0} source={source} style={dimension} />
26
     </SafeAreaView>
26
     </SafeAreaView>
27
   );
27
   );
28
 };
28
 };

BIN
example/src/bg.jpg Datei anzeigen


+ 7
- 0
example/yarn.lock Datei anzeigen

748
     invariant "^2.2.4"
748
     invariant "^2.2.4"
749
     prop-types "^15.7.2"
749
     prop-types "^15.7.2"
750
 
750
 
751
+"@react-native-community/blur@^3.4.1":
752
+  version "3.4.1"
753
+  resolved "https://registry.yarnpkg.com/@react-native-community/blur/-/blur-3.4.1.tgz#dec04c7d60dd6a4fa7e3af3506feefec804728d0"
754
+  integrity sha512-XhbS230J7BGuoEamjPFZ5jUWDOW16y+vD0Soyq9Iv1qL8R47esGl54bnfUSMH10WhNXrQzvPxkMzap+ONHpE2w==
755
+  dependencies:
756
+    prop-types "^15.5.10"
757
+
751
 "@react-native-community/cli-debugger-ui@^3.0.0":
758
 "@react-native-community/cli-debugger-ui@^3.0.0":
752
   version "3.0.0"
759
   version "3.0.0"
753
   resolved "https://registry.yarnpkg.com/@react-native-community/cli-debugger-ui/-/cli-debugger-ui-3.0.0.tgz#d01d08d1e5ddc1633d82c7d84d48fff07bd39416"
760
   resolved "https://registry.yarnpkg.com/@react-native-community/cli-debugger-ui/-/cli-debugger-ui-3.0.0.tgz#d01d08d1e5ddc1633d82c7d84d48fff07bd39416"

+ 5
- 9
src/index.js Datei anzeigen

2
 import React, { Component } from "react";
2
 import React, { Component } from "react";
3
 import { View, NativeModules, Platform, findNodeHandle } from "react-native";
3
 import { View, NativeModules, Platform, findNodeHandle } from "react-native";
4
 const { RNViewShot } = NativeModules;
4
 const { RNViewShot } = NativeModules;
5
-
6
-import type { Element, ElementRef, ElementType, Ref } from "react";
7
 import type { ViewStyleProp } from "react-native/Libraries/StyleSheet/StyleSheet";
5
 import type { ViewStyleProp } from "react-native/Libraries/StyleSheet/StyleSheet";
8
 import type { LayoutEvent } from "react-native/Libraries/Types/CoreEventTypes";
6
 import type { LayoutEvent } from "react-native/Libraries/Types/CoreEventTypes";
9
 
7
 
102
   }
100
   }
103
 }
101
 }
104
 
102
 
105
-export function captureRef<T: ElementType>(
106
-  input: number | ?View | Ref<T>,
103
+export function captureRef<T: React$ElementType>(
104
+  input: number | ?View | React$Ref<T>,
107
   optionsObject?: Object
105
   optionsObject?: Object
108
 ): Promise<string> {
106
 ): Promise<string> {
109
   ensureModuleIsLoaded();
107
   ensureModuleIsLoaded();
159
 type Props = {
157
 type Props = {
160
   options?: Object,
158
   options?: Object,
161
   captureMode?: "mount" | "continuous" | "update",
159
   captureMode?: "mount" | "continuous" | "update",
162
-  children: Element<*>,
160
+  children: React$Node,
163
   onLayout?: (e: *) => void,
161
   onLayout?: (e: *) => void,
164
   onCapture?: (uri: string) => void,
162
   onCapture?: (uri: string) => void,
165
   onCaptureFailure?: (e: Error) => void,
163
   onCaptureFailure?: (e: Error) => void,
168
 
166
 
169
 function checkCompatibleProps(props: Props) {
167
 function checkCompatibleProps(props: Props) {
170
   if (!props.captureMode && props.onCapture) {
168
   if (!props.captureMode && props.onCapture) {
171
-    console.warn(
172
-      "react-native-view-shot: a captureMode prop must be provided for `onCapture`"
173
-    );
169
+    // in that case, it's authorized if you call capture() yourself
174
   } else if (props.captureMode && !props.onCapture) {
170
   } else if (props.captureMode && !props.onCapture) {
175
     console.warn(
171
     console.warn(
176
       "react-native-view-shot: captureMode prop is defined but onCapture prop callback is missing"
172
       "react-native-view-shot: captureMode prop is defined but onCapture prop callback is missing"
251
     }
247
     }
252
   };
248
   };
253
 
249
 
254
-  onRef = (ref: ElementRef<*>) => {
250
+  onRef = (ref: React$ElementRef<*>) => {
255
     this.root = ref;
251
     this.root = ref;
256
   };
252
   };
257
 
253