-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
92 lines (91 loc) · 2.43 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Dimensions,
Text,
View,
TouchableOpacity,
} from 'react-native';
import ImagePicker from 'react-native-image-picker';
const {width, height}=Dimensions.get('window');
const styles=StyleSheet.create({
btn:{
width:width/2,
height:50,
backgroundColor:'blue',
borderRadius:6,
alignItems:"center",
justifyContent:'center',
}
});
const options = {
title: '选择图片',
cancelButtonTitle: '取消',
takePhotoButtonTitle: '拍照',
chooseFromLibraryButtonTitle: '图片库',
cameraType: 'back',
mediaType: 'photo',
videoQuality: 'high',
durationLimit: 10,
maxWidth: 600,
maxHeight: 600,
aspectX: 2,
aspectY: 1,
quality: 0.8,
angle: 0,
allowsEditing: false,
noData: false,
storageOptions: {
skipBackup: true,
path: 'images'
}
};
export default class App extends Component<{}> {
render() {
return (
<TouchableOpacity
style={styles.btn}
onPress={this.addTodo.bind(this)}
>
<Text style={{color:"#fff", fontSize:16}}>相册</Text>
</TouchableOpacity>
);
}
addTodo(){
ImagePicker.showImagePicker(options, (response) => {
if (response.didCancel) {
console.log('User cancelled image picker');
}else if (response.error) {
console.log('ImagePicker Error: ', response.error);
}else{
let source;
if(Platform.OS === 'android'){
source = {uri: response.uri, isStatic: true}
}else{
source = {uri: response.uri.replace('file://', ''), isStatic: true}
}
let file;
if(Platform.OS === 'android'){
file = response.uri
}else {
file = response.uri.replace('file://', '')
}
this.setState({
loading:true
});
this.props.onFileUpload(file,response.fileName||'未命名文件.jpg')
.then(result=>{
this.setState({
loading:false
})
})
}
});
}
}