componentdidmount中的this.props.navigation.setparams未定义

时间:2019-06-07 20:23:14

标签: react-native react-native-navigation

  

你好,我正在尝试更改componentDidMount中的navigationOptions的headerRight,但该道具   未定义。我相信我在做正确的事情叫setParams。   这是我的代码:

for f in ./temp/*"$1"*_trim.fastq; do
  seqtk seq -A "$f" >"${f%.fastq}.fasta"
done
  

社交在主要组件内部被调用,所以我相信范围可能与我需要的范围不同。

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
 }
});

0 个答案:

没有答案