react-navigation, how to set screen title before render? -


i using "react-navigation" , "react-native-localization" make multiple language ui app. far, every ui component displayed multiple languages after selecting languages, except titles of screens.

 export default class home extends component {     constructor(props) {      super(props);      this.loaddata();      this.state = {       ready: false     }; }  loaddata() { // set ui language     asyncstorage.getitem("language")      .then(value => {        console.log("home loaded language: " + value);        languages.setlanguage(value );        this.setstate({ ready: true });        console.log("home header: "+ languages.header)      })     .done();   }     static navigationoptions = {      title:languages.header    };        render() {             if (!this.state.ready) {                return <text>loading home ...</text>;             } else {               return (                <view style={styles.container}>                  <login />                </view>               );            }         }        } 

the above pretty how done, worked other components. loaded language correct, checked it. console printed correct text should displayed title of screen. somehow correct did not displayed title.

so, how can set title of screens before renders? suggestion how that?

you should load languages once, in "root" component. you'd keep "ready-check" , render app if languages loaded.

class root extends component {   state = { ready: false }    componentdidmount() {     asyncstorage.getitem("language")      .then(value => {        languages.setlanguage(value );        this.setstate({ ready: true });      });   }    render() {     if (!this.state.ready) return null;     return <app />;   } } 

this way, of components have chosen language available when render , able use in navigationoptions (and everywhere).


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -