我一直在努力寻找听起来很简单的事情。当调用onpressed时我一直试图获得按钮。尝试了几个组合器,但没有任何作用。有什么想法吗?
export default class JobScreen extends React.Component {
constructor(props) {
super(props);
}
static navigationOptions = ({navigation}) => ({
title: "Chat with"
});
onPressLearnMore(nav) {
// how do I update the title header
console.log("On Pressed" + nav)
}
render() {
const {navigate} = this.props.navigation;
return (
<View style={styles.container}>
<Button
onPress={() => {this.onPressLearnMore(navigate)}}
title="Learn More"
color="#841584"
/>
</View>
);
}
}
答案 0 :(得分:3)
由于navigationOptions
可以访问navigation
对象,因此您可以使用this.props.navigation.setParam({ title: ‘some title’ })
在当前屏幕上设置一些参数,然后在此navigationOptions
中访问它
static navigationOptions = ({ navigation }) => {
const { state: { params = {} } } = navigation;
return {
title: params.title || ‘default title’,
};
}