在响应本机中使用transform translateX从左到右和从右到左进行动画处理?

时间:2020-09-29 19:47:09

标签: reactjs react-native react-native-reanimated

我想从右到左和从左到右为我的组件设置动画:

const CardCashout: FC<CardCashoutProps> = ({ openCard }) => {
 const left = new Animated.Value(0);
  useEffect(() => {
    if (openCard)
      Animated.timing(left, {
        toValue: 0,
        duration: 5000,
        easing: Easing.inOut(Easing.ease),
      }).start();
    else {
      Animated.timing(left, {
        toValue: 222,
        duration: 5000,
        easing: Easing.out(Easing.ease),
      }).start();
    }
  }, [openCard]);
  return (
    <Animated.View style={{ transform: [{ translateX: left }] }}>
      <Text>CardCashout</Text>
    </Animated.View>
  );
};

当opencard为false时,向右转为动画,但是当opecard为true时我尝试切换它时,没有动画发生吗?

0 个答案:

没有答案