Parcourir la source

add many individual examples

Gaëtan Renaudeau il y a 4 ans
Parent
révision
2cf0d177f6
No account linked to committer's email address

+ 1
- 0
example/package.json Voir le fichier

@@ -29,6 +29,7 @@
29 29
     "@babel/runtime": "^7.5.5",
30 30
     "@react-native-community/eslint-config": "^0.0.5",
31 31
     "eslint": "^6.1.0",
32
+    "flow-bin": "0.98.0",
32 33
     "metro-react-native-babel-preset": "^0.55.0",
33 34
     "react-test-renderer": "16.8.6"
34 35
   }

+ 48
- 15
example/src/App.js Voir le fichier

@@ -2,9 +2,50 @@
2 2
 import React, { Fragment } from 'react';
3 3
 import { SafeAreaView, StatusBar, View, Text, TouchableOpacity, StyleSheet } from 'react-native';
4 4
 import { createStackNavigator, createAppContainer } from 'react-navigation';
5
+
6
+// To add a screen, import it and add it in screens
7
+
5 8
 import FullScreen from './Full';
6 9
 import ViewshootScreen from './Viewshoot';
7 10
 import TransparencyScreen from './Transparency';
11
+import VideoScreen from './Video';
12
+import WebViewScreen from './WebView';
13
+import MapViewScreen from './MapView';
14
+import GLReactV2Screen from './GLReactV2';
15
+import SVGUriScreen from './SVGUri';
16
+import ModalScreen from './Modal';
17
+
18
+const screens = {
19
+  Full: {
20
+    screen: FullScreen,
21
+  },
22
+  Video: {
23
+    screen: VideoScreen,
24
+  },
25
+  WebView: {
26
+    screen: WebViewScreen,
27
+  },
28
+  MapView: {
29
+    screen: MapViewScreen,
30
+  },
31
+  GLReactV2: {
32
+    screen: GLReactV2Screen,
33
+  },
34
+  SVGUri: {
35
+    screen: SVGUriScreen,
36
+  },
37
+  Modal: {
38
+    screen: ModalScreen,
39
+  },
40
+  Viewshoot: {
41
+    screen: ViewshootScreen,
42
+  },
43
+  Transparency: {
44
+    screen: TransparencyScreen,
45
+  },
46
+};
47
+
48
+///////////////////////////////////////////////////
8 49
 
9 50
 class HomeScreen extends React.Component {
10 51
   static navigationOptions = {
@@ -15,11 +56,15 @@ class HomeScreen extends React.Component {
15 56
     return (
16 57
       <Fragment>
17 58
         <StatusBar barStyle="dark-content" />
18
-        <SafeAreaView contentInsetAdjustmentBehavior="automatic">
59
+        <SafeAreaView>
19 60
           {Object.keys(screens).map(key => (
20 61
             <TouchableOpacity key={key} onPress={() => navigation.navigate(key)}>
21 62
               <View style={styles.entry}>
22
-                <Text style={styles.entryText}>{key}</Text>
63
+                <Text style={styles.entryText}>
64
+                  {(screens[key].screen.navigationOptions &&
65
+                    screens[key].screen.navigationOptions.title) ||
66
+                    key}
67
+                </Text>
23 68
               </View>
24 69
             </TouchableOpacity>
25 70
           ))}
@@ -35,23 +80,11 @@ const styles = StyleSheet.create({
35 80
     paddingHorizontal: 20,
36 81
   },
37 82
   entryText: {
38
-    fontSize: 28,
83
+    fontSize: 22,
39 84
     color: '#36f',
40 85
   },
41 86
 });
42 87
 
43
-const screens = {
44
-  Full: {
45
-    screen: FullScreen,
46
-  },
47
-  Viewshoot: {
48
-    screen: ViewshootScreen,
49
-  },
50
-  Transparency: {
51
-    screen: TransparencyScreen,
52
-  },
53
-};
54
-
55 88
 const AppNavigator = createStackNavigator({
56 89
   Home: {
57 90
     screen: HomeScreen,

+ 19
- 0
example/src/Desc.js Voir le fichier

@@ -0,0 +1,19 @@
1
+//@flow
2
+import React from 'react';
3
+import { StyleSheet, Text } from 'react-native';
4
+
5
+const styles = StyleSheet.create({
6
+  desc: {
7
+    marginHorizontal: 10,
8
+    marginVertical: 20,
9
+    fontSize: 14,
10
+    fontStyle: 'italic',
11
+    color: '#888',
12
+  },
13
+});
14
+
15
+const Desc = ({ desc }) => {
16
+  return <Text style={styles.desc}>{desc}</Text>;
17
+};
18
+
19
+export default Desc;

+ 1
- 1
example/src/Full.js Voir le fichier

@@ -234,7 +234,7 @@ const App = () => {
234 234
               <Picker
235 235
                 style={styles.input}
236 236
                 selectedValue={config.result}
237
-                onValueChange={result => setConfig({ ...config, result })}
237
+                onValueChange={r => setConfig({ ...config, result: r })}
238 238
               >
239 239
                 <Picker.Item label="tmpfile" value="tmpfile" />
240 240
                 <Picker.Item label="base64" value="base64" />

+ 50
- 0
example/src/GLReactV2.js Voir le fichier

@@ -0,0 +1,50 @@
1
+//@flow
2
+import React, { useState, useCallback } from 'react';
3
+import { SafeAreaView, Image } from 'react-native';
4
+import ViewShot from 'react-native-view-shot';
5
+import { Surface } from 'gl-react-native';
6
+import GL from 'gl-react';
7
+import Desc from './Desc';
8
+
9
+const shaders = GL.Shaders.create({
10
+  helloGL: {
11
+    frag: `
12
+precision highp float;
13
+varying vec2 uv;
14
+uniform float blue;
15
+void main () {
16
+  gl_FragColor = vec4(uv.x, uv.y, blue, 1.0);
17
+}`,
18
+  },
19
+});
20
+
21
+const HelloGL = GL.createComponent(
22
+  ({ blue }) => <GL.Node shader={shaders.helloGL} uniforms={{ blue }} />,
23
+  { displayName: 'HelloGL' },
24
+);
25
+
26
+const dimension = { width: 300, height: 300 };
27
+
28
+const GLReactV2 = () => {
29
+  const [source, setSource] = useState(null);
30
+  const onCapture = useCallback(uri => setSource({ uri }), []);
31
+  return (
32
+    <SafeAreaView>
33
+      <ViewShot onCapture={onCapture} captureMode="mount" style={dimension}>
34
+        <Surface width={300} height={300}>
35
+          <HelloGL blue={0.5} />
36
+        </Surface>
37
+      </ViewShot>
38
+
39
+      <Desc desc="above is a gl-react surface and below is a capture of it" />
40
+
41
+      <Image source={source} style={dimension} />
42
+    </SafeAreaView>
43
+  );
44
+};
45
+
46
+GLReactV2.navigationOptions = {
47
+  title: 'gl-react-native @ 2',
48
+};
49
+
50
+export default GLReactV2;

+ 38
- 0
example/src/MapView.js Voir le fichier

@@ -0,0 +1,38 @@
1
+//@flow
2
+import React, { useState, useCallback } from 'react';
3
+import { SafeAreaView, Image } from 'react-native';
4
+import ViewShot from 'react-native-view-shot';
5
+import MapView from 'react-native-maps';
6
+import Desc from './Desc';
7
+
8
+const dimension = { width: 300, height: 300 };
9
+
10
+const MapViewExample = () => {
11
+  const [source, setSource] = useState(null);
12
+  const onCapture = useCallback(uri => setSource({ uri }), []);
13
+  return (
14
+    <SafeAreaView>
15
+      <ViewShot onCapture={onCapture} captureMode="continuous" style={dimension}>
16
+        <MapView
17
+          initialRegion={{
18
+            latitude: 37.78825,
19
+            longitude: -122.4324,
20
+            latitudeDelta: 0.0922,
21
+            longitudeDelta: 0.0421,
22
+          }}
23
+          style={dimension}
24
+        />
25
+      </ViewShot>
26
+
27
+      <Desc desc="above is a map view and below is a continuous screenshot of it" />
28
+
29
+      <Image source={source} style={dimension} />
30
+    </SafeAreaView>
31
+  );
32
+};
33
+
34
+MapViewExample.navigationOptions = {
35
+  title: 'react-native-maps',
36
+};
37
+
38
+export default MapViewExample;

+ 81
- 0
example/src/Modal.js Voir le fichier

@@ -0,0 +1,81 @@
1
+//@flow
2
+import React, { Fragment, useState, useCallback, useRef } from 'react';
3
+import { StyleSheet, View, SafeAreaView, Text, Image, Modal } from 'react-native';
4
+import { captureScreen, captureRef } from 'react-native-view-shot';
5
+import Btn from './Btn';
6
+import Desc from './Desc';
7
+
8
+const styles = StyleSheet.create({
9
+  root: {
10
+    padding: 50,
11
+  },
12
+  preview: {
13
+    marginTop: 20,
14
+    width: 200,
15
+    height: 200,
16
+    borderWidth: 1,
17
+    borderColor: '#aaa',
18
+  },
19
+  modal: {
20
+    alignSelf: 'flex-end',
21
+    padding: 20,
22
+    backgroundColor: '#eee',
23
+  },
24
+  buttons: {
25
+    flexDirection: 'row',
26
+  },
27
+});
28
+
29
+const ModalExample = () => {
30
+  const [opened, setOpened] = useState(false);
31
+  const [source, setSource] = useState(null);
32
+  const modalRef = useRef();
33
+
34
+  const onOpenModal = useCallback(() => setOpened(true), []);
35
+
36
+  const onCapture = useCallback(uri => {
37
+    setSource({ uri });
38
+    setOpened(false);
39
+  }, []);
40
+
41
+  const onPressCapture = useCallback(() => {
42
+    captureScreen().then(onCapture);
43
+  }, [onCapture]);
44
+
45
+  const onPressCaptureModalContent = useCallback(() => {
46
+    captureRef(modalRef).then(onCapture);
47
+  }, [onCapture]);
48
+
49
+  return (
50
+    <Fragment>
51
+      <SafeAreaView>
52
+        <View style={styles.root}>
53
+          <Desc
54
+            desc="We can notice that, in current implementation, react-native-view-shot does not
55
+            screenshot Modal as part of a captureScreen."
56
+          />
57
+          <Btn onPress={onOpenModal} label="Open Modal" />
58
+          <Image source={source} style={styles.preview} resizeMode="contain" />
59
+        </View>
60
+      </SafeAreaView>
61
+
62
+      <Modal transparent animated animationType="slide" visible={opened}>
63
+        <SafeAreaView>
64
+          <View ref={modalRef} style={styles.modal}>
65
+            <Text>This is a modal</Text>
66
+            <View style={styles.buttons}>
67
+              <Btn onPress={onPressCapture} label="Capture Screen" />
68
+              <Btn onPress={onPressCaptureModalContent} label="Capture This" />
69
+            </View>
70
+          </View>
71
+        </SafeAreaView>
72
+      </Modal>
73
+    </Fragment>
74
+  );
75
+};
76
+
77
+ModalExample.navigationOptions = {
78
+  title: 'Modal',
79
+};
80
+
81
+export default ModalExample;

+ 30
- 0
example/src/SVGUri.js Voir le fichier

@@ -0,0 +1,30 @@
1
+//@flow
2
+import React, { useState, useCallback } from 'react';
3
+import { SafeAreaView, Image } from 'react-native';
4
+import ViewShot from 'react-native-view-shot';
5
+import SvgUri from 'react-native-svg-uri';
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 onCapture = useCallback(uri => setSource({ uri }), []);
13
+  return (
14
+    <SafeAreaView>
15
+      <ViewShot onCapture={onCapture} captureMode="continuous" style={dimension}>
16
+        <SvgUri width={200} height={200} source={require('./homer-simpson.svg')} />
17
+      </ViewShot>
18
+
19
+      <Desc desc="above is an SVG view and below is a continuous screenshot of it" />
20
+
21
+      <Image source={source} style={dimension} />
22
+    </SafeAreaView>
23
+  );
24
+};
25
+
26
+SvgUriExample.navigationOptions = {
27
+  title: 'react-native-svg-uri',
28
+};
29
+
30
+export default SvgUriExample;

+ 30
- 0
example/src/Video.js Voir le fichier

@@ -0,0 +1,30 @@
1
+//@flow
2
+import React, { useState, useCallback } from 'react';
3
+import { SafeAreaView, Image } from 'react-native';
4
+import ViewShot from 'react-native-view-shot';
5
+import Video from 'react-native-video';
6
+import Desc from './Desc';
7
+
8
+const dimension = { width: 300, height: 300 };
9
+
10
+const VideoExample = () => {
11
+  const [source, setSource] = useState(null);
12
+  const onCapture = useCallback(uri => setSource({ uri }), []);
13
+  return (
14
+    <SafeAreaView>
15
+      <ViewShot onCapture={onCapture} captureMode="continuous" style={dimension}>
16
+        <Video style={dimension} source={require('./broadchurch.mp4')} volume={0} repeat />
17
+      </ViewShot>
18
+
19
+      <Desc desc="above is a video and below is a continuous screenshot of it" />
20
+
21
+      <Image source={source} style={dimension} />
22
+    </SafeAreaView>
23
+  );
24
+};
25
+
26
+VideoExample.navigationOptions = {
27
+  title: 'react-native-video',
28
+};
29
+
30
+export default VideoExample;

+ 34
- 0
example/src/WebView.js Voir le fichier

@@ -0,0 +1,34 @@
1
+//@flow
2
+import React, { useState, useCallback } from 'react';
3
+import { SafeAreaView, Image } from 'react-native';
4
+import ViewShot from 'react-native-view-shot';
5
+import WebView from 'react-native-webview';
6
+import Desc from './Desc';
7
+
8
+const dimension = { width: 300, height: 300 };
9
+
10
+const WebViewExample = () => {
11
+  const [source, setSource] = useState(null);
12
+  const onCapture = useCallback(uri => setSource({ uri }), []);
13
+  return (
14
+    <SafeAreaView>
15
+      <ViewShot onCapture={onCapture} captureMode="continuous" style={dimension}>
16
+        <WebView
17
+          source={{
18
+            uri: 'https://github.com/gre/react-native-view-shot',
19
+          }}
20
+        />
21
+      </ViewShot>
22
+
23
+      <Desc desc="above is a webview and below is a continuous screenshot of it" />
24
+
25
+      <Image source={source} style={dimension} />
26
+    </SafeAreaView>
27
+  );
28
+};
29
+
30
+WebViewExample.navigationOptions = {
31
+  title: 'react-native-webview',
32
+};
33
+
34
+export default WebViewExample;

+ 5
- 0
example/yarn.lock Voir le fichier

@@ -2299,6 +2299,11 @@ flatted@^2.0.0:
2299 2299
   resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.1.tgz#69e57caa8f0eacbc281d2e2cb458d46fdb449e08"
2300 2300
   integrity sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==
2301 2301
 
2302
+flow-bin@0.98.0:
2303
+  version "0.98.0"
2304
+  resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.98.0.tgz#3361a03682326a83a5f0a864749f4f7f0d826bce"
2305
+  integrity sha512-vuiYjBVt82eYF+dEk9Zqa8hTSDvbhl/czxzFRLZm9/XHbJnYNMTwFoNFYAQT9IQ6ACNBIbwSTIfxroieuKja7g==
2306
+
2302 2307
 for-in@^1.0.2:
2303 2308
   version "1.0.2"
2304 2309
   resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"