【发布时间】:2018-04-03 06:05:12
【问题描述】:
我在我的 React Native 应用程序中使用反应导航,我想在用户单击应用程序右上角的保存按钮时调用函数 onSavePress()。
但是当我尝试调用 onSavePress 函数时,我的应用程序崩溃了,换句话说,它不像我从静态 navigationOptions 函数内部调用该函数。
下面是代码:
class TheFormScreen extends Component {
constructor(props)
{
super(props);
this.state = {
visible: true
};
}
state = {
isReady: false,
};
static navigationOptions = ({ navigation }) => ({
title: `${navigation.state.params.item.a1}`,
tabBarIcon: ({ tintColor }) => {
return <Icon name="phone" size={30} color={tintColor} />;
},
headerRight: (
<Btn
title='Done-'
onPress={() => { console.log(' on Press done on line 73 Form--Screen this.props=', this.props); navigation.goBack() }
}
/>
),
});
onDecline(){
// console.log(' onDecline clicked');
this.setState ({ showModal : false });
}
}
onDeleteProperty() {
// console.log(' onDelete clicked');
}
onSavePress(){
this.onClickToaster();
console.log( '101 - on click onSavePress ');
const { a1, a2 } = this.props;
this.props.propertySave({ a1, a2 });
}
【问题讨论】:
-
你不能在静态块中这样做。阅读有关 static 关键字的信息,以便您理解它。另外,要回答您的问题,请查看github.com/react-community/react-navigation/issues/145
标签: react-native react-navigation