UNPKG

@fruits-chain/react-native-xiaoshu

Version:
95 lines (91 loc) • 3.48 kB
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); } import React, { useRef, useMemo, memo } from 'react'; import { Animated } from 'react-native'; import { Svg, Circle } from 'react-native-svg'; import { getDefaultValue } from '../helpers'; import Theme from '../theme'; import { varCreator } from './style'; import useLoop from './useLoop'; const AnimatedCircle = Animated.createAnimatedComponent(Circle); const STROKE_WIDTH = 2; const Circular = _ref => { let { size, color } = _ref; const TOKENS = Theme.useThemeTokens(); const CV = Theme.createVar(TOKENS, varCreator); const AnimatedCircle0Value = useRef(new Animated.Value(0)).current; const AnimatedCircle1Value = useRef(new Animated.Value(0)).current; const AnimatedCircle2Value = useRef(new Animated.Value(0)).current; size = getDefaultValue(size, CV.loading_icon_size); color = getDefaultValue(color, CV.loading_icon_color); const circle1Props = useMemo(() => { const center = Math.floor(size / 2); const radios = Math.floor(center - STROKE_WIDTH / 2); return { cy: center, cx: center, r: radios }; }, [size]); const circle2Props = useMemo(() => { const center = Math.floor(size / 2); const radios = Math.floor(center - STROKE_WIDTH / 2 - center / 2); return { cy: center, cx: center, r: radios }; }, [size]); const half1Circle = useMemo(() => circle1Props.r * Math.PI, [circle1Props.r]); const half2Circle = useMemo(() => circle2Props.r * Math.PI, [circle2Props.r]); useLoop(AnimatedCircle0Value, 0, { toValue: 1, duration: CV.loading_icon_animation_duration }); useLoop(AnimatedCircle1Value, half1Circle, { toValue: -half1Circle * 2, duration: CV.loading_icon_animation_duration * 1.5 }); useLoop(AnimatedCircle2Value, half2Circle, { toValue: -half2Circle * 2, duration: CV.loading_icon_animation_duration * 2.5 }); const iconStyle = { justifyContent: 'center', alignItems: 'center', width: size, height: size, transform: [{ rotateZ: AnimatedCircle0Value.interpolate({ inputRange: [0, 1], outputRange: ['-90deg', '270deg'] }) }] }; return /*#__PURE__*/React.createElement(Animated.View, { style: iconStyle }, /*#__PURE__*/React.createElement(Svg, { width: "100%", height: "100%" // style={{ backgroundColor: 'rgba(0,0,0,0.2)' }} }, /*#__PURE__*/React.createElement(AnimatedCircle, _extends({}, circle1Props, { stroke: color, strokeWidth: STROKE_WIDTH, strokeDasharray: `${half1Circle},${half1Circle * 2}`, strokeLinecap: "round" // strokeDashoffset={half1Circle - half1Circle - half1Circle - 10} , strokeDashoffset: AnimatedCircle1Value, fill: "none" })), /*#__PURE__*/React.createElement(AnimatedCircle, _extends({}, circle2Props, { stroke: color, strokeWidth: STROKE_WIDTH, strokeDasharray: `${half2Circle},${half2Circle * 2}`, strokeLinecap: "round" // strokeDashoffset={half1Circle - half1Circle - half1Circle - 10} , strokeDashoffset: AnimatedCircle2Value, fill: "none" })))); }; export default /*#__PURE__*/memo(Circular); //# sourceMappingURL=loading-circular.js.map