import React, { Component } from 'react'; import { Animated, Easing } from 'react-native'; import Svg, { Path, G } from 'react-native-svg'; const AnimatePath = Animated.createAnimatedComponent(Path); interface EleAnimationProps { /** * 路径颜色 */ pathColor: any; /** * 动画时间 */ animateTime: number; } interface EleAnimationStates { strokeDashOffset: any; } export default class EleAnimation extends Component { static defaultProps = { pathColor: '#0078FF', animateTime: 2000, }; constructor(props: EleAnimationProps) { super(props); this.state = { strokeDashOffset: new Animated.Value(280), }; } componentDidMount() { // 使用炫酷的animated让小线段愉悦的奔跑 const animationLoading = Animated.timing(this.state.strokeDashOffset, { toValue: 0, easing: Easing.linear, duration: this.props.animateTime, }); Animated.loop(animationLoading).start(); } render() { return ( ); } }