react-native-animated-spinkit
Version:
A pure JavaScript port of SpinKit for React Native.
83 lines (79 loc) • 2.91 kB
JavaScript
function _extends() { _extends = Object.assign || 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); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import * as React from 'react';
import { Animated, View } from 'react-native';
import { defaultProps } from './SpinnerProps';
import AnimationContainer from './AnimationContainer';
import { loop } from './utils';
export default class Wander extends React.Component {
render() {
const {
size,
color,
style,
animating,
hidesWhenStopped,
...rest
} = this.props;
const wanderDistance = size * 0.75;
return /*#__PURE__*/React.createElement(AnimationContainer, {
initAnimation: () => ({
wander: value => ({
values: [value],
animation: loop({
duration: 2000,
value: value,
keyframes: [0, 25, 50, 75, 100]
})
})
}),
animating: animating
}, values => /*#__PURE__*/React.createElement(View, _extends({
style: [{
width: size,
height: size,
opacity: !animating && hidesWhenStopped ? 0 : 1
}, style]
}, rest), Array(3).fill(null).map((_, index) => /*#__PURE__*/React.createElement(View, {
key: index,
style: {
width: size,
height: size,
position: 'absolute',
transform: [{
rotate: "".concat(index * 90, "deg")
}]
}
}, /*#__PURE__*/React.createElement(Animated.View, {
style: {
width: size / 5,
height: size / 5,
backgroundColor: color,
position: 'absolute',
transform: [{
translateX: values.wander[0].interpolate({
inputRange: [0, 25, 50, 75, 100],
outputRange: [0, wanderDistance, wanderDistance, 0, 0]
})
}, {
translateY: values.wander[0].interpolate({
inputRange: [0, 25, 50, 75, 100],
outputRange: [0, 0, wanderDistance, wanderDistance, 0]
})
}, {
scale: values.wander[0].interpolate({
inputRange: [0, 25, 50, 75, 100],
outputRange: index % 2 === 0 ? [1, 0.6, 1, 0.6, 1] : [0.6, 1, 0.6, 1, 0.6]
})
}, {
rotate: values.wander[0].interpolate({
inputRange: [0, 25, 50, 75, 100],
outputRange: ['0deg', '-90deg', '-180deg', '-270deg', '-360deg']
})
}]
}
})))));
}
}
_defineProperty(Wander, "defaultProps", defaultProps);
//# sourceMappingURL=Wander.js.map