How to change the title bar of a navigation bar while viewing downloads

I need to read a single value and use it to set the title in the navigation bar.
I use react-native-router-fluxand I also use redux.
I turn to viewing, where I set the language and effect of fiery contraction.
All views get a new state and method render()that I can call:

console.log(this.props.language.language)

This is installed through redux. And I want to change the name of the navigation bar, for example:

Actions.refresh({title: I18n.t('main', {locale: this.props.language.language})})

But this slows down the application and does not work.
But I don’t know where to put it, if not in the method render.

+5
source share
5

render - , .

:

componentDidMount () {
  Actions.refresh(...)
}

, .

0

, .

constructor , , .

// Settings.js
var Settings = (function() {
  var language = "EN"; // The default language

  var getLanguage = function() {
    return language;
  };
  var setLanguage = function(lang) {
    language = lang;
  };

  return {
    getLanguage: getLanguage,
    setLanguage: setLanguage
  }
})();

export default Settings;

:

import Settings from './Settings';
... 
constructor(props) {
  super(props);
  this.state = {
    language: Settings.getLanguage()
  }
}

:

import Settings from './Settings';
... 
Settings.setLanguage('FR');

// Do something like reload here?
0

, React Lifecycle componentWillReceiveProps()

componentWillReceiveProps(nextProps){
    let { language } = nextProps.language;
    if (language && language != this.props.language.language) {
      Actions.refresh({title: I18n.t('main', {locale: language})})
    }
}
0

, , Router > .

Actions.refresh({key: 'somekey', title: I18n.t('main', {locale: this.props.language.language})})

, , , . , , Actions , .

, . , Action .

componentDidMount(){} componentWillReceiveProps(){}, , Redux .

setTimeout(() => {
   Actions.refresh({key: 'somekey', title: I18n.t('main', {locale: this.props.language.language})}, 200); // give him some space!
});

, .

0

, :

this.props.navigation.setParams({
    title: 'YOUR_DESIRED_TITLE_HERE',
});
0

Source: https://habr.com/ru/post/1670758/


All Articles