在svgMap上有2个像素点,我可以很容易地在这2个点之间画一条线或路径。我想在2秒内动画绘制路径。
这是我的代码
const [pointAPixels, setPointAPixels] = useState({ x: 0, y: 0 });
const [pointBPixels, setPointBPixels] = useState({ x: 0, y: 0 });
const AnimatedPath = Animated.createAnimatedComponent(Path);
const animationProgress = useSharedValue(0);
useEffect(() => {
animationProgress.value = 0;
animationProgress.value = withTiming(1, {
duration: 1500,
easing: Easing.linear,
// useNativeDriver: false, // Enlevez cette ligne si elle n'est pas nécessaire
});
}, [pointAGPS, pointBGPS]);
const animatedProps = useAnimatedProps(() => {
const length = interpolate(animationProgress.value, [0, 1], [100, 0]);
console.log(length, animationProgress.value);
return {
strokeDasharray: "10",
strokeDashoffset: length,
};
});
return (
<View>
<SvgFrance width={320} height={320} fill={black} />
<AnimatedPath
d={`M ${pointAPixels.x} ${pointAPixels.y} L ${pointBPixels.x} ${pointBPixels.y}`}
// d={pathData}
stroke="black"
strokeWidth="2"
// strokeOpacity={animationProgress}
// strokeDasharray="5" // Configurer ici la valeur de strokeDasharray
animatedProps={animatedProps}
/>
</Svg>
</View>
);
}
字符串
我把最重要的代码贴上去了。
我经常和
strokeDasharray: "10",
strokeDashoffset: length,
型
但我不知道路径的长度因为它总是在变...
1条答案
按热度按时间lawou6xi1#
我是这样解决的:
字符串