瀏覽代碼

auto commit

app
jfinn 3 年之前
父節點
當前提交
3a5df7bb7a
共有 1 個檔案被更改,包括 109 行新增1 行删除
  1. 109
    1
      mdev/rn_cam.native.js

+ 109
- 1
mdev/rn_cam.native.js 查看文件

@@ -1,6 +1,14 @@
1 1
 import React, { PureComponent } from 'react';
2 2
 import { AppRegistry, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
3 3
 import { RNCamera } from 'react-native-camera';
4
+import React, { Fragment, useState, useCallback, useRef } from 'react';
5
+import { StyleSheet, View, SafeAreaView, Text, Image, Modal } from 'react-native';
6
+
7
+import Btn from 'react-native-camera/example/src/Btn';
8
+import Desc from 'react-native-camera/example/src/Desc';
9
+
10
+
11
+
4 12
 
5 13
 class ExampleApp extends PureComponent {
6 14
   render() {
@@ -52,6 +60,15 @@ class ExampleApp extends PureComponent {
52 60
   };
53 61
 }
54 62
 
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
55 72
 const styles = StyleSheet.create({
56 73
   container: {
57 74
     flex: 1,
@@ -75,4 +92,95 @@ const styles = StyleSheet.create({
75 92
 });
76 93
 
77 94
 
78
-export {ExampleApp}
95
+
96
+
97
+const styles = StyleSheet.create({
98
+  root: {
99
+    padding: 50,
100
+  },
101
+  preview: {
102
+    marginTop: 20,
103
+    width: 200,
104
+    height: 200,
105
+    borderWidth: 1,
106
+    borderColor: '#aaa',
107
+  },
108
+  modal: {
109
+    alignSelf: 'flex-end',
110
+    padding: 20,
111
+    backgroundColor: '#eee',
112
+  },
113
+  buttons: {
114
+    flexDirection: 'row',
115
+  },
116
+});
117
+
118
+const ModalExample = () => {
119
+  const [opened, setOpened] = useState(false);
120
+  const [source, setSource] = useState(null);
121
+  const modalRef = useRef();
122
+
123
+  const onOpenModal = useCallback(() => setOpened(true), []);
124
+
125
+  const onCapture = useCallback(uri => {
126
+    setSource({ uri });
127
+    setOpened(false);
128
+  }, []);
129
+
130
+  const onPressCapture = useCallback(() => {
131
+    captureScreen().then(onCapture);
132
+  }, [onCapture]);
133
+
134
+  const onPressCaptureModalContent = useCallback(() => {
135
+    captureRef(modalRef).then(onCapture);
136
+  }, [onCapture]);
137
+
138
+  return (
139
+    <Fragment>
140
+      <SafeAreaView>
141
+        <View style={styles.root}>
142
+          <Desc
143
+            desc="We can notice that, in current implementation, react-native-view-shot does not
144
+            screenshot Modal as part of a captureScreen."
145
+          />
146
+          <Btn onPress={onOpenModal} label="Open Modal" />
147
+          <Image fadeDuration={0} source={source} style={styles.preview} resizeMode="contain" />
148
+        </View>
149
+      </SafeAreaView>
150
+
151
+      <Modal transparent animated animationType="slide" visible={opened}>
152
+        <SafeAreaView>
153
+          <View ref={modalRef} style={styles.modal}>
154
+            <Text>This is a modal</Text>
155
+            <View style={styles.buttons}>
156
+              <Btn onPress={onPressCapture} label="Capture Screen" />
157
+              <Btn onPress={onPressCaptureModalContent} label="Capture This" />
158
+            </View>
159
+          </View>
160
+        </SafeAreaView>
161
+      </Modal>
162
+    </Fragment>
163
+  );
164
+};
165
+
166
+ModalExample.navigationOptions = {
167
+  title: 'Modal',
168
+};
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+export {ExampleApp,ModalExample}

Loading…
取消
儲存