-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
129 lines (119 loc) · 3.18 KB
/
App.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import React, { useState } from 'react';
import { Text, View, StyleSheet } from 'react-native';
import { ImageBrowser } from 'expo-image-picker-multiple';
const App = () => {
const [chosenAssets, setChosenAssets] = useState([]);
const imagesCallback = (callback) => {
callback
.then((photos) => {
setChosenAssets(photos);
})
.catch((e) => console.log(e));
};
const updateHandler = (count, onSubmit) => {
console.log(`count: ${count} :: onSubmit: ${JSON.stringify(onSubmit)}`);
};
const renderSelectedComponent = (number) => (
<View style={styles.countBadge}>
<Text style={styles.countBadgeText}>{number}</Text>
</View>
);
const emptyStayComponent = <Text style={styles.emptyStay}>Empty =(</Text>;
const noCameraPermissionComponent = (
<Text style={styles.emptyStay}>No access to camera</Text>
);
const NameValueRow = ({ name, value }) => {
return (
<View style={styles.nameValueContainer}>
<Text style={styles.textName}>{name}: </Text>
<Text style={styles.textValue}>{value}</Text>
</View>
);
};
const AssetInfo = ({ assetInfo }) => {
//
// table of properties: https://docs.expo.io/versions/v39.0.0/sdk/media-library/#asset
//
return (
<View key={`${assetInfo.id}`} style={{ borderBottomWidth: 1 }}>
<NameValueRow name={'filename'} value={assetInfo.filename} />
<NameValueRow name={'mediaType'} value={assetInfo.mediaType} />
<NameValueRow name={'width'} value={assetInfo.width} />
<NameValueRow name={'height'} value={assetInfo.height} />
</View>
);
};
return (
<View style={[styles.flex, styles.container]}>
<ImageBrowser
max={4}
onChange={updateHandler}
callback={imagesCallback}
renderSelectedComponent={renderSelectedComponent}
emptyStayComponent={emptyStayComponent}
noCameraPermissionComponent={noCameraPermissionComponent}
/>
<View style={styles.divider} />
{chosenAssets.length > 0 ?
chosenAssets.map((asset) => <AssetInfo assetInfo={asset} />)
: <Text style={styles.textNoSelection}>No images selected</Text>}
<View style={styles.screenBottomPadding} />
</View>
);
};
export default App;
const styles = StyleSheet.create({
flex: {
flex: 1,
},
container: {
paddingTop: 50,
position: 'relative',
},
emptyStay: {
textAlign: 'center',
},
countBadge: {
paddingHorizontal: 8.6,
paddingVertical: 5,
borderRadius: 50,
position: 'absolute',
right: 3,
bottom: 3,
justifyContent: 'center',
backgroundColor: '#0580FF',
},
countBadgeText: {
fontWeight: 'bold',
alignSelf: 'center',
padding: 'auto',
color: '#ffffff',
},
divider: {
height: 1,
borderWidth: 3,
borderColor: 'purple',
},
nameValueContainer: {
flexDirection: 'row',
},
textName: {
width: 100,
textAlign: 'right',
paddingRight: 10,
},
textValue: {
fontWeight: 'bold',
},
screenBottomPadding: {
height: 30,
},
textNoSelection: {
fontSize: 20,
fontStyle: 'italic',
height: 50,
paddingTop: 20,
textAlign: 'center',
width: '100%',
},
});