Answer a question

Im using react-navigation for react-native. Is there an option to make that inactive tab screens get unmounted like unmountInactiveRoutes: true in DrawerNavigator?? I cant find something like unmountInactiveRoutes for BottomTabNavigator.

I have two stacknavigators inside a BottomTabNavigator and I want to unmount them automatically.

  • BottomTabNavigator
    • Stack1
      • Screen
      • Screen
    • Stack2
      • Screen
      • Screen

Answers

So I don't know if you can unmount components that are inactive personally I did not find it however this is my workaround withNavigationFocus(FocusStateLabel) and if isFocused is false. returning null. So this will give you more or less what you are looking for. If isFocused is true, you'll render what you usually render. If false you'll return null. resulting in the unmounting of your components

Some reference https://reactnavigation.org/docs/en/with-navigation-focus.html

Logo

React社区为您提供最前沿的新闻资讯和知识内容

更多推荐