-
Notifications
You must be signed in to change notification settings - Fork 0
/
Foli.js
86 lines (80 loc) · 2.05 KB
/
Foli.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
import React from "react";
import { Platform, StyleSheet, Text, View } from "react-native";
import { MapView } from "expo";
import { Ionicons } from "@expo/vector-icons";
export default class Foli extends React.Component {
constructor(props) {
super(props);
this.state = {
coordinate: new MapView.AnimatedRegion({
latitude: 0,
longitude: 0,
}),
};
}
componentWillReceiveProps(nextProps) {
const duration = 1500;
const nextCoordinate = {
latitude: nextProps.latitude,
longitude: nextProps.longitude,
};
const propsMatch =
this.props.latitude === nextProps.latitude &&
this.props.longitude === nextProps.longitude;
if (!propsMatch) {
if (Platform.OS === "android") {
if (this.marker) {
this.marker._component.animateMarkerToCoordinate(
nextCoordinate,
duration,
);
}
} else {
this.state.coordinate
.timing({
...nextCoordinate,
duration,
})
.start();
}
}
}
shouldComponentUpdate(nextProps, nextState) {
if (!nextProps.isInView) {
return false;
}
if (
this.props.latitude === nextProps.latitude &&
this.props.longitude === nextProps.longitude
) {
return false;
}
return true;
}
render() {
const { id, name, latitude, longitude } = this.props;
return (
<MapView.Marker.Animated
ref={marker => {
this.marker = marker;
}}
coordinate={this.state.coordinate}
>
<View
renderToHardwareTextureAndroid
style={{
alignItems: "center",
justifyContent: "center",
backgroundColor: "#fff",
paddingVertical: 2,
paddingHorizontal: 6,
borderRadius: 10,
}}
>
<Text style={{ fontSize: 14, color: "#555" }}>{name}</Text>
<Ionicons name="md-bus" size={32} color="green" />
</View>
</MapView.Marker.Animated>
);
}
}