【问题标题】:How do I animate React Navigation transitions using createBottomTabNavigator?如何使用 createBottomTabNavigator 为 React Navigation 过渡设置动画?
【发布时间】:2021-11-12 13:26:47
【问题描述】:

【问题讨论】:

  • 如果我的回答有帮助,请分享您的反馈。
  • 原来如此,谢谢。我只是还没有足够的声望来投票。

标签: android ios react-native react-navigation react-native-reanimated-v2


【解决方案1】:

只需创建一个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 创建&lt;FadeInView /&gt; 组件

【讨论】:

  • 非常感谢。但是,有没有办法在褪色页面上保持状态?启用 unmountOnBlur 会导致用户丢失所有导航历史记录。有没有一种方法可以实现相同的行为但保留所有状态逻辑?
  • 是的,有一种方法可以做到这一点,但您必须使用focus 事件监听器。 Triggering an action with a 'focus' event listener 并致电FadeAnimation
  • 使用 useFocusEffect hook snack.expo.dev/@pedrosousa/fade-animation-between-bottom-tabs 使其工作。现在下一步实际上是实现一个淡入淡出动画,它在屏幕内容之间而不是在 rootviewbackground(在本例中为空白屏幕)之间转换
  • 添加这个属性&lt;Tab.Navigator {...{ screenOptions,sceneContainerStyle }}&gt;const sceneContainerStyle={ backgroundColor:'#95a5a6' }你不会看到白屏。
猜你喜欢
  • 1970-01-01
  • 2020-12-15
  • 2020-05-02
  • 1970-01-01
  • 1970-01-01
  • 2020-11-24
  • 1970-01-01
  • 2021-05-23
  • 1970-01-01
相关资源
最近更新 更多