react-native - Reanimated v3 - 布局动画 - React-native 中的淡入和淡出

标签 react-native react-native-reanimated

我在有条件地淡入和淡出内容时遇到一些麻烦,因此它不会“弹出”。

这是我到目前为止所得到的,但似乎不起作用。我可能会错过什么?

我使用的是重新启动的 v3,其中 AnimatedLayout 已被删除。

const MyComponent = () => {

  const [didLoad, setDidLoad] = useState(false);

  useEffect(() => {
    const interval = setInterval(() => {
      setDidLoad(prev => !prev);
    }, 3000);

    return () => {
      clearInterval(interval);
    };
  }, []);

  return (
    <>
      {didLoad ? (
          <Animated.View
            entering={FadeIn}
            exiting={FadeOut}
            layout={Layout.duration(200).delay(200)}
          >
            <SkeletonPlaceholder borderRadius={4}>
              <SkeletonPlaceholder.Item alignItems="center" flexDirection="row">
                <SkeletonPlaceholder.Item
                  borderRadius={50}
                  height={20}
                  width={20}
                />

                <SkeletonPlaceholder.Item marginLeft={20}>
                  <SkeletonPlaceholder.Item height={25} width={120} />

                  <SkeletonPlaceholder.Item
                    height={25}
                    marginTop={6}
                    width={80}
                  />
                </SkeletonPlaceholder.Item>
              </SkeletonPlaceholder.Item>
            </SkeletonPlaceholder>
          </Animated.View>
        ) : (
          <Animated.View
            entering={FadeIn}
            exiting={FadeOut}
            layout={Layout.duration(200).delay(200)}
          >
            <View style={tw`flex-row items-center gap-2`}>
              <Icon name="chevron-right" />

              <Icon name="chevron-left" />

              <Icon name="map" />

              <Icon name="home" />
            </View>
          </Animated.View>
        )}
    </>
  )
}

最佳答案

您必须向动画 View 添加关键点,请参阅this小吃,我已经按照您在问题中提到的相同方式添加了动画,并且它正在工作。

       <Animated.View
            key="fede3"  // add this
            entering={FadeIn}
            exiting={FadeOut}
            layout={Layout.duration(2000).delay(200)}
          >
           <View 
              key="view1"  // add this
              style={styles.view1}>
           </View>
       </Animated.View>

here github repo 上有类似问题可供引用。

P.S.我注意到,当调试器处于“打开”状态时,进入/退出动画不起作用。

关于react-native - Reanimated v3 - 布局动画 - React-native 中的淡入和淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76905813/

相关文章:

React-Native - reanimated-bottom-sheet - 无法向上/向下拖动底部工作表

javascript - 我如何在 React 导航中从 Drawer Stack 导航到 Switch Stack?

react-native - 在react-native-reanimated中继续循环动画

android - 在 React native 项目中构建失败 'A problem occurred configuring project ' :react-native-reanimated'.

objective-c - 调用 RCTDirectEventBlock 不会触发 JS 代码

reactjs - React-native-reanimated:无法解析 "./useValue"

javascript - 错误 : Failed to initialize react-native-reanimated library

react-native - 如何使用Expo解析 "Duplicate module name: react-native"

react-native - 区分 react 导航中选项卡中的滑动和单击导航

javascript - React Native timemixin 取消定时器超时