forked from FaridSafi/react-native-gifted-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomView.js
82 lines (74 loc) · 1.98 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
70
71
72
73
74
75
76
77
78
79
80
81
82
import { Linking } from 'expo'
import PropTypes from 'prop-types'
import React from 'react'
import {
Platform,
StyleSheet,
TouchableOpacity,
ViewPropTypes,
} from 'react-native'
const MapView = Platform.select({
web: () => require('react-native-web-maps'),
default: () => require('react-native-maps'),
})
export default class CustomView extends React.Component {
static propTypes = {
currentMessage: PropTypes.object,
containerStyle: ViewPropTypes.style,
mapViewStyle: ViewPropTypes.style,
}
static defaultProps = {
currentMessage: {},
containerStyle: {},
mapViewStyle: {},
}
openMapAsync = async () => {
const { currentMessage: { location = {} } = {} } = this.props
const url = Platform.select({
ios: `http://maps.apple.com/?ll=${location.latitude},${location.longitude}`,
default: `http://maps.google.com/?q=${location.latitude},${location.longitude}`,
})
try {
const supported = await Linking.canOpenURL(url)
if (supported) {
return Linking.openURL(url)
}
alert('Opening the map is not supported.')
} catch ({ message }) {
alert(message)
}
}
render() {
const { currentMessage, containerStyle, mapViewStyle } = this.props
if (currentMessage.location) {
return (
<TouchableOpacity
style={[styles.container, containerStyle]}
onPress={this.openMapAsync}
>
<MapView
style={[styles.mapView, mapViewStyle]}
region={{
latitude: currentMessage.location.latitude,
longitude: currentMessage.location.longitude,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
scrollEnabled={false}
zoomEnabled={false}
/>
</TouchableOpacity>
)
}
return null
}
}
const styles = StyleSheet.create({
container: {},
mapView: {
width: 150,
height: 100,
borderRadius: 13,
margin: 3,
},
})