如何使用 createBottomTabNavigator 为 React Navigation 转换设置动画?

How do I animate React Navigation transitions using createBottomTabNavigator?

我花了最后一天的时间试图找出如何使用反应导航实现简单的淡入淡出屏幕过渡,但我找不到一种方法让它与底部标签导航器一起工作。有人可以帮我吗?我已经广泛阅读了文档,但动画似乎只能通过堆栈导航器使用。

你能在这个零食演示中实现转换吗?

https://snack.expo.io/?platform=android&name=Native%20Stack%20Navigator%20%7C%20React%20Navigation&dependencies=%40expo%2Fvector-icons%40*%2C%40react-native-community%2Fmasked-view%40*%2Creact-native-gesture-handler%40*%2Creact-native-pager-view%40*%2Creact-native-paper%40%5E4.7.2%2Creact-native-reanimated%40*%2Creact-native-safe-area-context%40*%2Creact-native-screens%40*%2Creact-native-tab-view%40%5E3.0.0%2C%40react-navigation%2Fbottom-tabs%406.0.4%2C%40react-navigation%2Fdrawer%406.1.3%2C%40react-navigation%2Felements%401.0.4%2C%40react-navigation%2Fmaterial-bottom-tabs%406.0.4%2C%40react-navigation%2Fmaterial-top-tabs%406.0.2%2C%40react-navigation%2Fnative-stack%406.0.5%2C%40react-navigation%2Fnative%406.0.2%2C%40react-navigation%2Fstack%406.0.6&hideQueryParams=true&sourceUrl=https%3A%2F%2Freactnavigation.org%2Fexamples%2F6.x%2Ftab-based-navigation-minimal.js

只需创建一个 Animated.View 并将其附加到您的屏幕上。

const FadeHomeScreen = (props) => (
  <FadeInView>
    <HomeScreen {...props} />
  </FadeInView>
);

然后将其用于 Tab.Screen

<Tab.Screen name="Home" component={FadeHomeScreen} />

然后在 screenOptions

中添加 unmountOnBlur: true
const screenOptions = {
    unmountOnBlur: true,
    headerShown: false,
};

<Tab.Navigator {...{ screenOptions }}>

代码: https://snack.expo.dev/@fanish/native-stack-navigator-%7C-react-navigation

您也可以使用 react-native-reanimated 创建 <FadeInView /> 组件