-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomView.js
69 lines (65 loc) · 1.88 KB
/
CustomView.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
import React from 'react';
import {
Linking,
MapView,
Platform,
StyleSheet,
TouchableOpacity,
View,
} from 'react-native';
export default class CustomView extends React.Component {
render() {
if (this.props.currentMessage.location) {
return (
<TouchableOpacity style={[styles.container, this.props.containerStyle]} onPress={() => {
const url = Platform.select({
ios: `http://maps.apple.com/?ll=${this.props.currentMessage.location.latitude},${this.props.currentMessage.location.longitude}`,
android: `http://maps.google.com/?q=${this.props.currentMessage.location.latitude},${this.props.currentMessage.location.longitude}`
});
Linking.canOpenURL(url).then(supported => {
if (supported) {
return Linking.openURL(url);
}
}).catch(err => {
console.error('An error occurred', err);
});
}}>
<MapView
style={[styles.mapView, this.props.mapViewStyle]}
region={{
latitude: this.props.currentMessage.location.latitude,
longitude: this.props.currentMessage.location.longitude,
}}
annotations={[{
latitude: this.props.currentMessage.location.latitude,
longitude: this.props.currentMessage.location.longitude,
}]}
scrollEnabled={false}
zoomEnabled={false}
/>
</TouchableOpacity>
);
}
return null;
}
}
const styles = StyleSheet.create({
container: {
},
mapView: {
width: 150,
height: 100,
borderRadius: 13,
margin: 3,
},
});
CustomView.defaultProps = {
currentMessage: {},
containerStyle: {},
mapViewStyle: {},
};
CustomView.propTypes = {
currentMessage: React.PropTypes.object,
containerStyle: View.propTypes.style,
mapViewStyle: View.propTypes.style,
};