react-native - React Native Reanimated 2 为 SVG 路径的长度设置动画
问题描述
我正在尝试将 SVG 路径的长度从 0 动画到 React Native Reanimated 2 中的全长。这是我的示例路径:
const AnimatedPath = Animated.createAnimatedComponent(Path);
const animatedProps = useAnimatedProps(() => {
const path =
`M${width * 0.182} ${height * 0.59} ` +
`L${width * 0.443} ${height * 0.59} ` +
`L${width * 0.443} ${height * 0.39} `;
return {
d: path,
};
});
return (
<Svg height="100%" width="100%">
<AnimatedPath animatedProps={animatedProps} fill="none" stroke="red" strokeWidth="5" />
</Svg>
);
我尝试在路径宽度上添加一些插值,但没有成功。我还尝试查看 Redash 的 interpolatePath() 实现,但它似乎采用两条路径作为输出范围。还有什么我应该看的吗?
解决方案
您需要使用useAnimatedStyle
代替useAnimatedProps
,并使用 计算组件(由 Animated 包装)的d
值,基于您使用 0 更改为 1 的一些共享值。Path
useDerivedValue
progress
withTiming
推荐阅读
- windows - Powershell如何将远程目标与本地目标进行比较以发现差异
- flutter - 什么是 Canvas.save 和 Canvas.restore?
- rest - 加特林测试中的高响应时间
- javascript - 在 Testflight 版本中 React Native 元素的位置错误
- javascript - 反应在单击时访问列表组件的属性
- xamarin - 当我尝试上传微软商店时,UWP / Xamarin 在提交测试中崩溃
- c# - 将参数发送到 Razor 页面 RCL NET Core
- arrays - Powershell 从包含大量字符串的大文本文件中删除任何行
- makefile - Makefile:最后附加的文本无法识别
- swiftui - NavigationView 分层堆栈中的 SwiftUI TabView 在屏幕顶部有额外的空间