-
Notifications
You must be signed in to change notification settings - Fork 6
/
RefreshIndicator.js
53 lines (46 loc) · 1.05 KB
/
RefreshIndicator.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
/**
* @flow weak
*/
'use strict';
import React, {
PropTypes,
} from 'react';
import {
ActivityIndicatorIOS,
StyleSheet,
} from 'react-native';
/**
* A default refresh indicator. This component will likely change so copy and
* paste this code if you rely on it.
*/
class RefreshIndicator extends React.Component {
static propTypes = {
progress: PropTypes.number.isRequired,
active: PropTypes.bool.isRequired,
};
shouldComponentUpdate(nextProps) {
let { progress, active } = this.props;
return (progress !== nextProps.progress) || (active !== nextProps.active);
}
render() {
let { progress, active } = this.props;
let animatedStyle = {
transform: [
{ rotate: `${progress * 2 * Math.PI}rad` },
],
};
return (
<ActivityIndicatorIOS
animating={active}
hidesWhenStopped={progress === 0}
style={[styles.container, animatedStyle]}
/>
);
}
}
let styles = StyleSheet.create({
container: {
marginVertical: 16,
},
});
module.exports = RefreshIndicator;