forked from Expensify/react-native-share-menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Share.js
106 lines (99 loc) · 2.55 KB
/
Share.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import React, {useEffect, useState} from 'react';
import {View, Text, Pressable, Image, StyleSheet} from 'react-native';
import {ShareMenuReactView} from 'react-native-share-menu';
const Button = ({onPress, title, style}) => (
<Pressable onPress={onPress}>
<Text style={[{fontSize: 16, margin: 16}, style]}>{title}</Text>
</Pressable>
)
const Share = () => {
const [sharedData, setSharedData] = useState('');
const [sharedMimeType, setSharedMimeType] = useState('');
const [sending, setSending] = useState(false);
useEffect(() => {
ShareMenuReactView.data().then(({mimeType, data}) => {
setSharedData(data);
setSharedMimeType(mimeType);
});
}, []);
return (
<View style={styles.container}>
<View style={styles.header}>
<Button
title="Dismiss"
onPress={() => {
ShareMenuReactView.dismissExtension();
}}
style={styles.destructive}
/>
<Button
title={sending ? "Sending..." : 'Send'}
onPress={() => {
setSending(true);
setTimeout(() => {
ShareMenuReactView.dismissExtension();
}, 3000);
}}
disabled={sending}
style={sending ? styles.sending : styles.send}
/>
</View>
{sharedMimeType === 'text/plain' && <Text>{sharedData}</Text>}
{sharedMimeType.startsWith('image/') && (
<Image
style={styles.image}
resizeMode="contain"
source={{uri: sharedData}}
/>
)}
<View style={styles.buttonGroup}>
<Button
title="Dismiss with Error"
onPress={() => {
ShareMenuReactView.dismissExtension('Dismissed with error');
}}
style={styles.destructive}
/>
<Button
title="Continue In App"
onPress={() => {
ShareMenuReactView.continueInApp();
}}
/>
<Button
title="Continue In App With Extra Data"
onPress={() => {
ShareMenuReactView.continueInApp({hello: 'from the other side'});
}}
/>
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
},
header: {
flexDirection: 'row',
justifyContent: 'space-between',
},
destructive: {
color: 'red',
},
send: {
color: 'blue',
},
sending: {
color: 'grey',
},
image: {
width: '100%',
height: 200,
},
buttonGroup: {
alignItems: 'center',
},
});
export default Share;