我想在onPress上添加多个功能。所以我有这样的onPress功能。但这不起作用。
navigateToScreen = (route) => () => {
const navigateAction = NavigationActions.navigate({
routeName: route
});
this.props.navigation.dispatch(navigateAction);
}
onButtonPress() {
this.navigateToScreen('Home', { isStatusBarHidden: false })
}
render() {
return (
<View style={styles.container}>
<TouchableOpacity
style={styles.menuItem}
onPress={() => {this.onButtonPress.bind(this)}
>
...
navigateToScreen
无效,让我知道原因。
答案 0 :(得分:1)
应该是:
onPress={() => this.onButtonPress()}
或:
onPress={this.onButtonPress.bind(this)} // bind in constructor for better performance
或:
onButtonPress = () => {
...
onPress={this.onButtonPress}
此外,您的navigateToScreen
还有额外的参数:
navigateToScreen = (route, options) => {