-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathPulseLoader.js
119 lines (104 loc) · 2.55 KB
/
PulseLoader.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
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { View, Image, TouchableOpacity, Animated, Easing } from 'react-native';
import Pulse from './Pulse';
export default class LocationPulseLoader extends React.Component {
constructor(props) {
super(props);
this.state = {
circles: []
};
this.counter = 1;
this.setInterval = null;
this.anim = new Animated.Value(1);
}
componentDidMount() {
this.setCircleInterval();
}
setCircleInterval() {
this.setInterval = setInterval(this.addCircle.bind(this), this.props.interval);
this.addCircle();
}
addCircle() {
this.setState({ circles: [...this.state.circles, this.counter] });
this.counter++;
}
onPressIn() {
Animated.timing(this.anim, {
toValue: this.props.pressInValue,
duration: this.props.pressDuration,
easing: this.props.pressInEasing,
}).start(() => clearInterval(this.setInterval));
}
onPressOut() {
Animated.timing(this.anim, {
toValue: 1,
duration: this.props.pressDuration,
easing: this.props.pressOutEasing,
}).start(this.setCircleInterval.bind(this));
}
render() {
const { size, avatar, avatarBackgroundColor, interval } = this.props;
return (
<View style={{
flex: 1,
backgroundColor: 'transparent',
justifyContent: 'center',
alignItems: 'center',
}}>
{this.state.circles.map((circle) => (
<Pulse
key={circle}
{...this.props}
/>
))}
<TouchableOpacity
activeOpacity={1}
onPressIn={this.onPressIn.bind(this)}
onPressOut={this.onPressOut.bind(this)}
style={{
transform: [{
scale: this.anim
}]
}}
>
<Image
source={{ uri: avatar }}
style={{
width: size,
height: size,
borderRadius: size/2,
backgroundColor: avatarBackgroundColor
}}
/>
</TouchableOpacity>
</View>
);
}
}
LocationPulseLoader.propTypes = {
interval: PropTypes.number,
size: PropTypes.number,
pulseMaxSize: PropTypes.number,
avatar: PropTypes.string.isRequired,
avatarBackgroundColor: PropTypes.string,
pressInValue: PropTypes.number,
pressDuration: PropTypes.number,
borderColor: PropTypes.string,
backgroundColor: PropTypes.string,
getStyle: PropTypes.func,
};
LocationPulseLoader.defaultProps = {
interval: 2000,
size: 100,
pulseMaxSize: 250,
avatar: undefined,
avatarBackgroundColor: 'white',
pressInValue: 0.8,
pressDuration: 150,
pressInEasing: Easing.in,
pressOutEasing: Easing.in,
borderColor: '#D8335B',
backgroundColor: '#ED225B55',
getStyle: undefined,
};