@td-design/react-native
Version:
react-native UI组件库
77 lines • 2.33 kB
JavaScript
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React, { PureComponent } from 'react';
import { Animated, StyleSheet } from 'react-native';
import Box from '../box';
import Indicator from './Indicator';
export default class UIActivityIndicator extends PureComponent {
static displayName = 'UIActivityIndicator';
static defaultProps = {
color: 'rgb(0, 0, 0)',
count: 12,
size: 36
};
renderComponent = _ref => {
let {
index,
count,
progress
} = _ref;
const {
size,
color: backgroundColor
} = this.props;
const angle = index * 360 / count;
const layerStyle = {
transform: [{
rotate: angle + 'deg'
}]
};
const inputRange = Array.from(new Array(count + 1), (_, index) => index / count);
const outputRange = Array.from(new Array(count), (_, index) => Math.max(1.0 - index * (1 / (count - 1)), 0));
for (let j = 0; j < index; j++) {
outputRange.unshift(outputRange.pop());
}
outputRange.unshift(...outputRange.slice(-1));
const barStyle = {
width: size / 10,
height: size / 4,
borderRadius: size / 20,
backgroundColor,
opacity: progress.interpolate({
inputRange,
outputRange
})
};
return /*#__PURE__*/React.createElement(Animated.View, {
style: [styles.layer, layerStyle],
key: index
}, /*#__PURE__*/React.createElement(Animated.View, {
style: barStyle
}));
};
render() {
const {
style,
size: width,
size: height,
...props
} = this.props;
return /*#__PURE__*/React.createElement(Box, {
style: style
}, /*#__PURE__*/React.createElement(Indicator, _extends({
style: {
width,
height
},
renderComponent: this.renderComponent
}, props)));
}
}
const styles = StyleSheet.create({
layer: {
...StyleSheet.absoluteFillObject,
justifyContent: 'flex-start',
alignItems: 'center'
}
});
//# sourceMappingURL=UIActivityIndicator.js.map