|
@@ -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 fadeDuration={0} 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;
|