Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to re-render screens/components in tab navigator ? #39

Closed
kaiyes opened this issue Oct 1, 2017 · 5 comments
Closed

how to re-render screens/components in tab navigator ? #39

kaiyes opened this issue Oct 1, 2017 · 5 comments

Comments

@kaiyes
Copy link
Contributor

kaiyes commented Oct 1, 2017

Since we are using redux to control the navigation, is that making the screens inside tab navigator not re- mounting on tab change ? For example, if I go to tab x, and then go to some other tab, then return to tab x again, tab x doesn't remount/reload. if I console log inside componentDidMount, nothing comes out. So the component is being mounted once only. How can we make the component remount everytime the tab change ? thanks in advance

@kaiyes
Copy link
Contributor Author

kaiyes commented Oct 1, 2017

@kaiyes
Copy link
Contributor Author

kaiyes commented Oct 2, 2017

So apparently in React-navigation, it is not possible now to re-render a screen on tab change. There is a work around that was merged via react-navigation/react-navigation#1335 which onTabbarPress. Using that, one can plugin a modal into any tab navigator. The modal renders every time it is called. Plugging the subscription into that modal page also makes the badge reactive. This is quite an ugly hack to make this work. Makes me want to leave react navigation for something else. May be react-native-router-flux which seems to be the flavour of react router of this month

@EQuimper
Copy link
Owner

EQuimper commented Oct 2, 2017

With the help of a hoc I did that on one of my app

componentDidUpdate(prevProps) {
    if (prevProps.isFocused !== this.props.isFocused) {
      this._getInfo();
    }
  }

https://github.com/pmachowski/react-navigation-is-focused-hoc

@kaiyes
Copy link
Contributor Author

kaiyes commented Oct 2, 2017

Yeah came across that. There is another one as well.
https://github.com/satya164/react-navigation-addons
After doing this:

import { enhance } from 'react-navigation-addons';

export default Stacks = enhance(StackNavigator)({
  Home: { screen: HomeScreen },
  Settings: { screen: SettingsScreen },
});

Then gotta do this:

    this.props.navigation.addListener('change', this._handleStateChange);
  }

@EQuimper
Copy link
Owner

EQuimper commented Oct 2, 2017

O wow thank for this one, :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants