-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
156 lines (140 loc) · 4.3 KB
/
test.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import React, { PureComponent } from 'react';
import {
TouchableOpacity,
StyleSheet,
Platform,
ActivityIndicator,
View,
Text,
Image,
ToastAndroid,
AppRegistry
} from 'react-native';
var ImagePicker = require('react-native-image-picker');
import Icon from 'react-native-vector-icons/Ionicons';
import { Switch } from './Switch';
import Button from './Button';
import ButtonProvider from './ButtonProvider';
import ImageButtonProvider from './ImageButtonProvider';
import ImageButton from './ImageButton';
const btnNormal = require('./images/btn_bg_normal.png');
const btnSelect = require('./images/btn_bg_selected.png');
const options = {
quality: 0.8,
maxWidth: 500,
maxHeight: 500,
title: null,
cancelButtonTitle: '取消',
takePhotoButtonTitle: '拍照',
chooseFromLibraryButtonTitle: '从相册上传',
cameraType: 'back',
mediaType: 'photo',
noData: false,
storageOptions: {
skipBackup: true,
path: 'images'
}
};
export default class Test extends PureComponent {
constructor(props) {
super(props);
this.state = {
avatarSource: null,
selected: true,
borderColor: '#00baff',
page: 'second',
iconValue: 'hello',
}
}
_onSelect = (item) => {
this.setState({ page: item.props.name, iconValue: item.key });
}
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<ButtonProvider
selected={this.state.page}
style={{ marginTop: 20 }}
selectedStyle={{ color: 'red' }}
selectedIconStyle={{ borderWidth: 2, borderColor: 'red' }}
onSelect={item => this._onSelect(item)}
>
<Text name="first">First</Text>
<Text name="second">Second</Text>
</ButtonProvider>
<ImageButtonProvider
style={{ marginTop: 20 }}
selected={this.state.page}
textStyle={{ color: 'red' }}
selectedTextStyle={{ color: 'blue' }}
image={require('./images/btn_bg_normal.png')}
selectedImage={require('./images/btn_bg_selected.png')}
onSelect={item => this._onSelect(item)}>
<Text name="first">1</Text>
<Text name="second">2</Text>
</ImageButtonProvider>
<View style={{ flex: 1, marginTop: 20, flexDirection: 'row', justifyContent: 'center' }}>
<ImageButton
style={{ height: 50 }}
selected={this.state.selected}
textStyle={{ color: 'blue' }}
selectedTextStyle={{ color: 'red' }}
image={require('./images/btn_bg_normal.png')}
selectedImage={require('./images/btn_bg_selected.png')}
onSelect={item => { this.setState({ selected: !this.state.selected }); }}
title='ImageButton1'
/>
<ImageButton
style={{ height: 50 }}
selected={false}
textStyle={{ color: 'blue' }}
selectedTextStyle={{ color: 'red' }}
image={require('./images/btn_bg_normal.png')}
selectedImage={require('./images/btn_bg_selected.png')}
title='测试2'
/>
</View>
<View style={{ height: 50, width: 80, alignItems: 'center', justifyContent: 'center', }} >
<Image style={styles.image} source={require('./images/btn_bg_normal.png')} />
</View>
</View >
)
}
choosePic = () => {
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);
} else {
let source = { uri: response.uri };
// You can also display the image using data:
// let source = { uri: 'data:image/jpeg;base64,' + response.data };
this.setState({
avatarSource: source
});
}
})
}
}
const styles = StyleSheet.create({
cameraBtn: {
padding: 5,
height: 50,
width: 100,
alignItems: 'center',
},
uploadAvatar: {
height: 100,
width: 100,
alignItems: 'center',
marginTop: 20,
},
image: {
flex: 1,
resizeMode: 'contain',
},
});