初学react-native 动画使目标绕圆运动

初学react-native 动画使目标绕圆运动

import { Animated, Text, View, Easing } from ‘react-native’;

const FadeInView = (props) => {
const tim = 300; //圆的半径
const fadeAnim = useRef(new Animated.Value(tim)).current
const fadeAnim1 = useRef(new Animated.Value(0)).current
const fadeAnim2 = useRef(new Animated.Value(-tim)).current
React.useEffect(() => {
Animated.loop(Animated.sequence( //loop循环执行动画
[
Animated.timing( //
fadeAnim, //
{
toValue: -tim, //
duration: 2000, //
easing:Easing.linear(),
useNativeDriver: false
}
),
Animated.timing( //
fadeAnim2, //
{
toValue: tim, //
duration: 2000, //
easing:Easing.linear(),
useNativeDriver: false
}
)
])).start(); // 开始执行动画
fadeAnim.addListener((va)=>{ //此处运用勾股定理运算圆运动的坐标
fadeAnim1.setValue(Math.sqrt(tim*tim-(Number(JSON.stringify(va.value))Number(JSON.stringify(va.value)))))
})
fadeAnim2.addListener((va)=>{
fadeAnim.setValue(va.value)
fadeAnim1.setValue(-Math.sqrt(timtim-(Number(JSON.stringify(va.value))*Number(JSON.stringify(va.value)))))
})
}, [fadeAnim])

return (
<Animated.View //
style={{
…props.style,
marginBottom:fadeAnim,
marginLeft:fadeAnim1, //
}}
>
{props.children}
</Animated.View>
);
}

/
export default () => {
return (
<View style={{flex: 1, alignItems: ‘center’, justifyContent: ‘center’}}>
<FadeInView style={{width: 250, height: 50, backgroundColor: ‘powderblue’}}>
<Text style={{fontSize: 28, textAlign: ‘center’, margin: 10}}>Fading in


)
}
欢迎各位大佬提意见

上一篇:【解决方法】未能正确加载“VaCodeInspectionsPackage”包


下一篇:C/C++ 实现VA/RVA/FOA互相转换