动画启动失败 REACT-NATIVE

时间:2021-04-13 15:42:22

标签: react-native animation

我正在尝试使用动画组件创建底部模态。

这是打开和关闭模态并声明动画将控制的代码:

 const state = {
    opacity: new Animated.Value(0),
    container: new Animated.Value(height),
    modal: new Animated.Value(height),
  };

  const openModal = () => {
    Animated.sequence([
      Animated.timing(state.container, {toValue: 0, duration: 100}),
      Animated.timing(state.opacity, {toValue: 1, duration: 300}),
      Animated.spring(state.modal, {
        toValue: 0,
        bounciness: 5,
        useNativeDriver: true,
      }),
      ,
    ]).start();
  };

  const closeModal = () => {
    Animated.sequence([
      Animated.timing(state.modal, {
        toValue: height,
        duration: 250,
        useNativeDriver: true,
      }),
      Animated.timing(state.opacity, {toValue: 0, duration: 300}),
      Animated.timing(state.container, {toValue: height, duration: 100}),
      ,
    ]).start();
  };

  useEffect(() => {
    if (show) {
      openModal();
    } else {
      closeModal();
    }
  }, [show]);

但我从动画中得到了一个例外:

Undefined is not an object animation[current].start

有人可以帮忙吗?

0 个答案:

没有答案