LocationTextView.js
2.62 KB
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
import React, {Component} from 'react';
import {
View,
Text,
TouchableOpacity,
NativeModules
} from 'react-native';
const defaultHeight = (50);
const HPading = (16);
const VPading = (6);
export default class LocationTextView extends Component {
constructor(props) {
super(props);
this.state = {
address: ''
}
this.attrData = this.props.attrData;
this.extendData = JSON.parse(this.attrData.data);
}
getAddress() {
let _this = this;
NativeModules.system.getLocation().then(data => {
console.log('address', data);
if (!!JSON.parse(data).cityCode) {
let addressData = JSON.parse(data);
_this.setState({
address: addressData.formattedAddress
});
let result = {latitude: addressData.latitude, longitude: addressData.longitude, ip: '', name: addressData.formattedAddress}
this.attrData.value = JSON.stringify(result);
} else {
return;
}
});
}
render() {
let {name, code, type, description, isRequired, isPreview} = this.attrData;
let {placeholder, buttonText} = this.extendData;
return (
<TouchableOpacity
activeOpacity={1}
onPress={()=>this.getAddress()}
style={{
flex:1,
minHeight:defaultHeight,
paddingVertical:VPading,
paddingHorizontal:HPading,
justifyContent:'space-around',
backgroundColor:'#fff',
flexDirection: 'row'
}}
>
<View style={{flexDirection: 'row',width:50}}>
{isRequired&&<Text style={{ color: "#FF3030" }}>* {" "}</Text>}
{!isRequired&&<Text style={{ color: "#fff" }}>* {" "}</Text>}
<Text style={{fontSize: 16, color: 'rgba(0, 0, 0, 1)', }}>{name||""}</Text>
</View>
<Text
style={{flex:1, fontSize: 14, color: 'black', backgroundColor: 'white', textAlign: 'left', marginLeft:4, marginRight:4}}
numberOfLines={2}>{(this.state.address && this.state.address.length > 0) ? this.state.address:''}</Text>
{/** 获取按钮 */}
<Text style={{fontSize: 16, color: global.homeColor,width:60,textAlign:'right'}}
>{(this.state.address && this.state.address.length > 0) ? '刷新':'获取'}</Text>
</TouchableOpacity>
);
}
}