【发布时间】:2018-04-05 10:49:26
【问题描述】:
我想知道有没有一种方法可以使用headerRight onPress 来做一些事情,比如调用Alert:
我在MyPet.js 中有一个函数,代码如下:
_alert=()=>{
alert('saving')
}
在router.js 中,我有一个列表,列出了我习惯于使用如下代码进行导航的所有屏幕:
export const MyPatientStack = StackNavigator({
MyPatient: {
screen: MyPatient,
navigationOptions: {
tabBarLabel: 'My Patient',
tabBarIcon: ({ tintColor, focused }) => <FontAwesome name="wheelchair" size={25} color={tintColor} />,
headerTitle: 'My Patient',
headerStyle: {
backgroundColor: '#8B0000',
},
headerLeft: <HeaderBackButton tintColor="#FFF" onPress={() => navigation.goBack()} />,
// and here I want to call the function of _alert() from MyPet.js
headerRight: <FontAwesome name='search' size={20} color="#FFF" onPress={_alert()}/>,
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
textAlign:'center',
flex:1
},
}
}
})
试过了,代码找不到变量_alert
我该怎么做?
欢迎任何反馈
【问题讨论】:
标签: javascript react-native react-navigation