소스 검색

Add 2 examples

Gaëtan Renaudeau 5 년 전
부모
커밋
4114c4474e
No account linked to committer's email address
5개의 변경된 파일124개의 추가작업 그리고 3개의 파일을 삭제
  1. 1
    0
      example/package.json
  2. 52
    0
      example/src/ART.js
  3. 11
    3
      example/src/App.js
  4. 48
    0
      example/src/Canvas.js
  5. 12
    0
      example/yarn.lock

+ 1
- 0
example/package.json 파일 보기

@@ -14,6 +14,7 @@
14 14
     "lodash": "^4.17.15",
15 15
     "react": "16.8.6",
16 16
     "react-native": "0.60.4",
17
+    "react-native-canvas": "^0.1.33",
17 18
     "react-native-gesture-handler": "^1.3.0",
18 19
     "react-native-maps": "^0.25.0",
19 20
     "react-native-reanimated": "^1.2.0",

+ 52
- 0
example/src/ART.js 파일 보기

@@ -0,0 +1,52 @@
1
+//@flow
2
+import React, { useState, useCallback } from 'react';
3
+import { SafeAreaView, Image, View } from 'react-native';
4
+import ViewShot from 'react-native-view-shot';
5
+import { Surface, Group, Shape, Path } from '@react-native-community/art';
6
+import Desc from './Desc';
7
+
8
+const dimension = { width: 300, height: 300 };
9
+
10
+const ARTExample = () => {
11
+  const [source, setSource] = useState(null);
12
+  const onCapture = useCallback(uri => setSource({ uri }), []);
13
+  return (
14
+    <SafeAreaView>
15
+      <ViewShot onCapture={onCapture} captureMode="mount" style={dimension}>
16
+        <View
17
+          style={{
18
+            height: 100,
19
+            alignItems: 'center',
20
+            justifyContent: 'center',
21
+            backgroundColor: 'blue',
22
+          }}
23
+        >
24
+          <Surface width={200} height={100}>
25
+            <Group>
26
+              <Shape d="M 0,50 L 320,60" stroke="red" strokeWidth={10} />
27
+            </Group>
28
+          </Surface>
29
+          <View
30
+            style={{
31
+              width: 10,
32
+              height: 10,
33
+              backgroundColor: 'orange',
34
+              position: 'absolute',
35
+              top: 50,
36
+            }}
37
+          />
38
+        </View>
39
+      </ViewShot>
40
+
41
+      <Desc desc="ART overlapping test" />
42
+
43
+      <Image source={source} style={dimension} />
44
+    </SafeAreaView>
45
+  );
46
+};
47
+
48
+ARTExample.navigationOptions = {
49
+  title: '@react-native-community/art',
50
+};
51
+
52
+export default ARTExample;

+ 11
- 3
example/src/App.js 파일 보기

@@ -11,8 +11,10 @@ import TransparencyScreen from './Transparency';
11 11
 import VideoScreen from './Video';
12 12
 import WebViewScreen from './WebView';
13 13
 import MapViewScreen from './MapView';
14
+import CanvasScreen from './Canvas';
14 15
 import GLReactV2Screen from './GLReactV2';
15 16
 import SVGUriScreen from './SVGUri';
17
+import ARTScreen from './ART';
16 18
 import ModalScreen from './Modal';
17 19
 
18 20
 const screens = {
@@ -25,15 +27,21 @@ const screens = {
25 27
   WebView: {
26 28
     screen: WebViewScreen,
27 29
   },
30
+  SVGUri: {
31
+    screen: SVGUriScreen,
32
+  },
33
+  ART: {
34
+    screen: ARTScreen,
35
+  },
36
+  Canvas: {
37
+    screen: CanvasScreen,
38
+  },
28 39
   MapView: {
29 40
     screen: MapViewScreen,
30 41
   },
31 42
   GLReactV2: {
32 43
     screen: GLReactV2Screen,
33 44
   },
34
-  SVGUri: {
35
-    screen: SVGUriScreen,
36
-  },
37 45
   Modal: {
38 46
     screen: ModalScreen,
39 47
   },

+ 48
- 0
example/src/Canvas.js 파일 보기

@@ -0,0 +1,48 @@
1
+//@flow
2
+import React, { useRef, useState, useEffect, useCallback } from 'react';
3
+import { SafeAreaView, Image, View } from 'react-native';
4
+import ViewShot from 'react-native-view-shot';
5
+import { Surface, Group, Shape } from '@react-native-community/art';
6
+import Desc from './Desc';
7
+import Canvas from 'react-native-canvas';
8
+
9
+const dimension = { width: 300, height: 300 };
10
+
11
+const CanvasRendering = ({ onDrawn }) => {
12
+  const ref = useRef();
13
+  useEffect(() => {
14
+    const ctx = ref.current.getContext('2d');
15
+    ctx.fillStyle = '#eee';
16
+    ctx.fillRect(0, 0, ref.current.width, ref.current.height);
17
+    ctx.fillStyle = 'red';
18
+    ctx.fillRect(120, 30, 60, 60);
19
+    ctx.fillStyle = 'blue';
20
+    ctx.fillRect(140, 50, 60, 60);
21
+    const timeout = setTimeout(onDrawn, 500); // hack. react-native-canvas have no way to tell when it's executed
22
+    return () => clearTimeout(timeout);
23
+  }, []);
24
+  return <Canvas ref={ref} style={dimension} />;
25
+};
26
+
27
+const CanvasExample = () => {
28
+  const [source, setSource] = useState(null);
29
+  const viewShotRef = useRef();
30
+  const onCapture = useCallback(() => {
31
+    viewShotRef.current.capture().then(uri => setSource({ uri }));
32
+  }, []);
33
+  return (
34
+    <SafeAreaView>
35
+      <ViewShot ref={viewShotRef} style={dimension}>
36
+        <CanvasRendering onDrawn={onCapture} />
37
+      </ViewShot>
38
+
39
+      <Image source={source} style={dimension} />
40
+    </SafeAreaView>
41
+  );
42
+};
43
+
44
+CanvasExample.navigationOptions = {
45
+  title: 'react-native-canvas',
46
+};
47
+
48
+export default CanvasExample;

+ 12
- 0
example/yarn.lock 파일 보기

@@ -1641,6 +1641,11 @@ cross-spawn@^6.0.0, cross-spawn@^6.0.5:
1641 1641
     shebang-command "^1.2.0"
1642 1642
     which "^1.2.9"
1643 1643
 
1644
+ctx-polyfill@^1.1.4:
1645
+  version "1.1.4"
1646
+  resolved "https://registry.yarnpkg.com/ctx-polyfill/-/ctx-polyfill-1.1.4.tgz#08420bc5c540d08ac36d05720ca503c65e302d65"
1647
+  integrity sha1-CEILxcVA0IrDbQVyDKUDxl4wLWU=
1648
+
1644 1649
 debounce@^1.2.0:
1645 1650
   version "1.2.0"
1646 1651
   resolved "https://registry.yarnpkg.com/debounce/-/debounce-1.2.0.tgz#44a540abc0ea9943018dc0eaa95cce87f65cd131"
@@ -4302,6 +4307,13 @@ react-lifecycles-compat@^3.0.4:
4302 4307
   resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
4303 4308
   integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==
4304 4309
 
4310
+react-native-canvas@^0.1.33:
4311
+  version "0.1.33"
4312
+  resolved "https://registry.yarnpkg.com/react-native-canvas/-/react-native-canvas-0.1.33.tgz#e38a650e7d57b42faa717e7f3a1285d63d40e0f3"
4313
+  integrity sha512-rYnMcU+xB0O00Dz+77xHQcnemkt1gf9dHukNzhilLN0nQbT0JwbF/fsVOZNlqucSpuWVr4LyKhFVrAE/qebBAQ==
4314
+  dependencies:
4315
+    ctx-polyfill "^1.1.4"
4316
+
4305 4317
 react-native-gesture-handler@^1.3.0:
4306 4318
   version "1.3.0"
4307 4319
   resolved "https://registry.yarnpkg.com/react-native-gesture-handler/-/react-native-gesture-handler-1.3.0.tgz#d0386f565928ccc1849537f03f2e37fd5f6ad43f"