-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
76 lines (75 loc) · 2.2 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
/*This is an example of Image Picker in React Native*/
import React from 'react';
import { StyleSheet, Text, View, Button, Image } from 'react-native';
var ImagePicker = require('react-native-image-picker');
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
filePath: {},
};
}
chooseFile = () => {
var options = {
title: 'Select Image',
customButtons: [
{ name: 'customOptionKey', title: 'Choose Photo from Custom Option' },
],
storageOptions: {
skipBackup: true,
path: 'images',
},
};
ImagePicker.showImagePicker(options, response => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
alert(response.customButton);
} else {
let source = response;
// You can also display the image using data:
// let source = { uri: 'data:image/jpeg;base64,' + response.data };
this.setState({
filePath: source,
});
}
});
};
render() {
return (
<View style={styles.container}>
<View style={styles.container}>
{/*<Image
source={{ uri: this.state.filePath.path}}
style={{width: 100, height: 100}} />*/}
<Image
source={{
uri: 'data:image/jpeg;base64,' + this.state.filePath.data,
}}
style={{ width: 100, height: 100 }}
/>
<Image
source={{ uri: this.state.filePath.uri }}
style={{ width: 250, height: 250 }}
/>
<Text style={{ alignItems: 'center' }}>
{this.state.filePath.uri}
</Text>
<Button title="Choose File" onPress={this.chooseFile.bind(this)} />
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});