React Native Animated.sequence 在动画之间有滞后

React Native Animated.sequence has lag between animations

提问人:Vadim Setsko 提问时间:11/16/2023 最后编辑:Vadim Setsko 更新时间:11/16/2023 访问量:14

问:

尝试将两个动画与 Animated.sequence 组合在一起时遇到了问题。动画之间几乎没有明显的延迟(延迟),但这对我的应用程序中的用户体验至关重要。这在慢动作视频记录中清晰可见。在示例中,下面的是我的动画演示此问题的简化版本。在我的示例中,光标移动了 800 毫升秒,然后停止,然后又移动了 800 毫升秒。如何避免在动画之间停止?

export const TestAnimation = () => {
  const { Layout } = useTheme();
  let cursorPosition = useRef(new Animated.Value(0)).current;
  const firstAnimation = Animated.timing(cursorPosition, {
    toValue: 150,
    duration: 800,
    easing: Easing.linear,
    useNativeDriver: true,
  });
  const secondAnimation = Animated.timing(cursorPosition, {
    toValue: 300,
    duration: 800,
    easing: Easing.linear,
    useNativeDriver: true,
  });

  const combinedAnimation = Animated.sequence([
    firstAnimation,
    secondAnimation,
  ]);
  return (
    <View style={[Layout.fill, Layout.alignItemsCenter, Layout.relative]}>
      <Animated.View
        style={[
          Layout.absolute,
          Styles.cursor,
          {
            transform: [
              {
                translateX: cursorPosition,
              },
            ],
          },
        ]}
      />
      <Button
        title="Start Animation"
        onPress={() => {
          combinedAnimation.start();
        }}
      />
      <Button
        title="Reset Animation"
        onPress={() => {
          cursorPosition.setValue(0);
          combinedAnimation.reset();
        }}
      />
    </View>
  );
};

通过切换到 ,此行为已部分得到纠正,但它会带来其他问题。useNativeDriver: false

React-Native 动画 延迟 滞后

评论


答: 暂无答案