mirror of
https://github.com/expo/react-native-refreshable-scroll-view.git
synced 2026-11-15 09:18:09 -10:00
54 lines
1.0 KiB
JavaScript
54 lines
1.0 KiB
JavaScript
/**
|
|
* @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;
|