我要在单击按钮时导航到下一个屏幕。以下是我的LoginView.js文件。我不知道是什么原因。我检查了许多线程,但仍未获得正确答案。
import React, { Component } from 'react';
import { View, TextInput, TouchableOpacity, Image, Text, Keyboard } from 'react-native';
import PropTypes from 'prop-types';
import styles from './styles';
class LoginView extends Component {
constructor(props) {
super(props);
this.state = { mobilenumber: null, devicetoken: "ef1b82a0d41dad60" }
}
onPress = () => {
Keyboard.dismiss();
console.log("&&&", this.state.mobilenumber, this.state.devicetoken);
this.props.onLogin(this.state.mobilenumber, this.state.devicetoken);
}
render() {
return (
<View style={styles.container}>
<Image
style={styles.image}
source={require('./logo.png')}
/>
<TextInput
style={styles.input}
placeholder='Enter your mobile number'
onChangeText={value => this.setState({ mobilenumber: value })}
/>
<TouchableOpacity onPress={this.onPress}>
<View style={styles.button}>
<Text style={styles.buttonText}>Login</Text>
</View>
</TouchableOpacity>
</View>
);
}
}
LoginView.propTypes = {
onLogin: PropTypes.func
};
export default LoginView;
下面在我的LoginContainer.js文件中显示了我正在分派传递值的代码段。
class LoginContainer extends Component {
constructor(props) {
super(props);
}
render() {
return <LoginView {...this.props} />;
}
}
function mapStateToProps() {
return {};
}
function mapDispatchToProps(dispatch) {
return {
onLogin: (mobilenumber, devicetoken) => dispatch(loginActions.requestLogin(mobilenumber, devicetoken))
};
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(LoginContainer);