-
Notifications
You must be signed in to change notification settings - Fork 4
/
PulsingCircle.js
59 lines (49 loc) · 1.07 KB
/
PulsingCircle.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
/* eslint react-native/no-color-literals:0 */
import React, { Component } from 'react'
import {
Animated,
StyleSheet,
View } from 'react-native'
const PULSING_INTERVAL = 500
const CIRCLE_RADIUS = 10
const styles = StyleSheet.create({
circle: {
height: CIRCLE_RADIUS * 2,
width: CIRCLE_RADIUS * 2,
backgroundColor: '#ff1133',
borderRadius: CIRCLE_RADIUS,
}
})
class PulsingCircle extends Component {
constructor (props) {
super(props)
this.state = {
scale: new Animated.Value(1),
}
}
componentDidMount () {
this.props.pulse && this.cyclicAnimate()
}
cyclicAnimate () {
Animated.sequence([
Animated.timing(
this.state.scale, {
toValue: 1.1,
duration: PULSING_INTERVAL,
}),
Animated.timing(
this.state.scale, {
toValue: 1,
duration: PULSING_INTERVAL,
}),
]).start(() => this.cyclicAnimate())
}
render () {
return (<View { ...this.props }>
<Animated.View style={ [ styles.circle, { transform: [ { scale: this.state.scale } ] } ] } />
</View>)
}
}
PulsingCircle.propTypes = {
}
export default PulsingCircle