-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
104 lines (85 loc) · 2.34 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
import React, { Component } from 'react';
import { Colors } from 'react-native/Libraries/NewAppScreen';
import ImagePicker from 'react-native-image-picker';
import { StyleSheet,View,Text,TouchableOpacity,Image } from 'react-native';
export default class App extends Component {
state = {
imagePicked: null,
};
constructor(props) {
super(props);
this.pickphoto = this.pickphoto.bind(this);
}
pickphoto(){
const options = {
quality: 1.0,
maxWidth: 500,
maxHeight: 500,
storageOptions: {
skipBackup: true,
},
};
ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled photo picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
let source = {uri: response.uri};
this.setState({
imagePicked: source,
});
}
});
}
render() {
return (
<View style={styles.body}>
<Text style={{textAlign:'center',fontSize:20,paddingBottom:10,marginBottom:100}} >Pick Images from Camera & Gallery</Text>
<View style={styles.mainSection}>
<Image style={styles.image} source={this.state.imagePicked}/>
<TouchableOpacity onPress={this.pickphoto.bind(this)} style={styles.btn} >
<Text style={styles.btnText}>Pick a photo</Text>
</TouchableOpacity>
</View>
</View>
);
}
};
const styles = StyleSheet.create({
body: {
backgroundColor: Colors.white,
justifyContent: 'center',
borderColor: 'black',
borderWidth: 1,
height: "100%" ,
width: "100%"
},
mainSection: {
alignItems: 'center',
marginTop:10
},
btn: {
width: 225,
height: 60,
backgroundColor: '#a29bfe',
alignItems: 'center',
justifyContent: 'center',
borderRadius: 3,
marginBottom:10
},
btnText: {
textAlign: 'center',
color: 'white',
fontSize: 14,
fontWeight:'bold'
},
image: {
width: 400,
height: 400,
marginBottom:200,
},
});