react-native - componentdidmount 中的 this.props.navigation.setparams 未定义
问题描述
您好,我正在尝试更改 componentDidMount 中 navigationOptions 的 headerRight 但是道具未定义。我相信我做对了它被称为 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.
};
}
});
解决方案
推荐阅读
- python - 在 excel 中搜索一行以使用 Python 从关联行中接收数据
- c# - 为什么我看到.Cast 之间的差异
() 和 .Select(a => (int)a)? - python - 从上游客户端 172.17.0.1 读取响应标头时上游超时
- php - 将 Magento 1.9 移动到新服务器,但所有页面都给出 404
- java - NettyConnectorProvider (jersey-netty-connector) 在 Get Request 中不发送查询参数
- mqtt - MQTT:Broker 在将上一次发布的 publish_complete 消息发送给客户端之前发送新消息
- c# - 为什么我的 ASP.net 解决方案中有两个启动项目的“Global.asax.cs”文件没有被调用?
- join - Apache Kafka - KStream with KStream Join latest messages
- android - 如何以编程方式删除android中的电池优化?
- java - 如何为堆栈内存中的多个请求加载 Servlet 函数