我正在开发一个反应本机应用程序,我需要对 svg 文件的一部分进行动画处理(围绕中心点旋转)。如何访问我想要制作动画的组件?
我尝试将 svg 文件转换为 jsx 格式。但我仍然无法访问要旋转的组件
应用程序.js:
import React from 'react';
import { StyleSheet, Text, View, Animated } from 'react-native';
import SvgComponent from './assets/hotFan';
class App extends React.Component {
constructor(props){
super(props);
this.animation = new Animated.Value(0);
}
render(){
const rotation = this.animation.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '360deg']
});
return (
<Animated.View style={{transform: [{rotate: rotation}]}}>
<SvgComponent/>
</Animated.View>
);
}
componentDidMount() {
Animated.loop(
Animated.timing(this.animation, {toValue: 1, duration: 2000})
).start();
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
export default App;
我不能把整个组件代码放在这里,因为它超过了字符限制。但您可以使用https://www.smooth-code.com/open-source/svgr/playground/将https://drive.google.com/file/d/1lKaSWTO1_0cQQN6rtdaw_yWE9qa5nSjV/view?usp=sharing转换为 jsx 文件
实际代码旋转整个组件,但内部箭头是应该旋转的,而不是整个组件。