我正在尝试覆盖HeaderBackButton,并且我已经成功做到了,但是问题是我不能在HeaderBackButton onPress中使用goBack,我无法访问onPress内的导航对象HeaderBackButton的按钮。
我正在使用这段代码
static navigationOptions = {
title: 'Operation Screen',
headerLeft: (
<HeaderBackButton
onPress={ ()=>{
console.log('HeaderBackButton');
// Do some custom stuff
navigation.goBack();
}}
/>
)
};
只需将其定义为一个函数。您可以将navigation
作为参数
static navigationOptions = ({ navigation }) => {
return {
title: 'Operation Screen',
headerLeft: (
<HeaderBackButton
onPress={() => {
console.log('HeaderBackButton');
// Do some custom stuff
navigation.goBack();
}}
/>
)
}
}