react-navigation / redux-helpers

Redux middleware and utils for React Navigation
Other
296 stars 43 forks source link

TabNavigator inside StackNavigator has wrong state when going back to default tab #21

Closed SEUH closed 6 years ago

SEUH commented 6 years ago

I have a TabNavigator inside a StackNavigator

const Nav = StackNavigator( {
    Tabs: {
      screen: TabNavigator({
          home: {
            screen: HomeScreen, ...
          },
          points: {
            screen: PointsScreen,  ...
          },
          account: {
            screen: AccountScreen,  ...
          }

Now i have a middleware for my redux store which basically logs me the navigation state


Current Behavior

On my android phone i swipe left (to 'points'), then i swipe right (back to 'home' (default)) which is all displayed correctly but in the navigation state, it says that the tabnavigator is still on index 1.

image

Expected Behavior

Normally the navigation state should change correctly. It only doesn't change if i swipe to the "home" (default) tab.

How to reproduce

I use ignite but i did the Redux Integration 'tutorial' (also altered the ignite base code to the correct one in the tutorial) and logged me the navigation state. If there's a need for a replication app i can do one, but it will take some time.

Your Environment

software version
react-navigation 1.5.4
react-navigation-redux-helpers 1.0.3
react-redux 5.0.6

Am i missing something here?

Update 1:

Further investigation with reactotron shows that the navigation state really doesn't change when i swipe to the 'home' tab (but every other navigation works, it's just the 'home' tab (index 0))

Ashoat commented 6 years ago

Sorry, the docs are a little out-of-date. Updating them is on my to-do list.

Are you using the new export initializeListeners? Call it in your top-level component's componentDidMount'. If that doesn't work, try using createNavigationReducer to construct your reducer (it wraps your navigator, and returns a navigation reducer to be called by your master reducer).

If neither of those solve the issue, then yes unfortunately I'll need an Expo Snack that reproduces the issue so I can investigate on my end.

SEUH commented 6 years ago

I included createNavigationReducer to create my reducer and called initializeListeners in my main app component but that doesn't change anything. I will try to 'export' my project within the next days.

SEUH commented 6 years ago

I've found the problem. I had the "addNavigationHelpers" function called outside my navigations render function so it basically was only called once and caused this weird error.

Ashoat commented 6 years ago

Awesome! Glad you figured it out.