this.props.navigation.setparams в componentdidmount не определено - PullRequest
1 голос
/ 07 июня 2019

Здравствуйте, я пытаюсь изменить headerRight навигационных параметров в componentDidMount, однако реквизит не определено Я считаю, что я делаю правильно, как это называется setParams. Вот мой код:

componentDidMount(){
try{
  AsyncStorage.getItem('experience').then(experience => {
    const objExperience = new Experience();
    const newExperience = JSON.parse(experience);

    showExperience = objExperience.showMyLevel((newExperience));

    this.props.navigation.setParams({
      headerTitle: 'Social',
      headerLeft:  <Icon style={{paddingLeft: 20}}
                         name="md-menu" 
                         size={30} 
                         onPress={()=> this.props.navigation.openDrawer()}/>,
      headerRight: <Text style={{paddingRight: 20}}>Level {showExperience}</Text>,
    });
  });
}
catch(e){
  console.log('error from AsyncStorage in' + arguments.callee.name + ': ', e);
}
}
const Social = createStackNavigator({
 SocialScreen:{
   screen: SocialScreen,
   navigationOptions: ({navigation})=>{
     const { params } = navigation.state;

     return params;
   }
 },
 Detail:{
   screen: Detail
 }
});

Социальная сеть вызывается внутри основного компонента, поэтому я считаю, что, возможно, область действия отличается от того, что мне нужно.

const DashboardTabNavigator = createBottomTabNavigator({
  Social,
  Work,
  ToDo
},
{
navigationOptions: ({navigation})=>{
  const {routeName} = navigation.state.routes[navigation.state.index];

  return {
    header: null,
    headerTitle: routeName, //it puts the name of the tab on the top of the 
    screen.
  };
}
});
...