【发布时间】:2017-02-20 09:21:22
【问题描述】:
所以“onPress={this.onPressButton.bind(this)}”导致我的应用程序失败?
我能做些什么来解决它。我相信它与(这个)变得不受约束或什么有关?
我正在渲染一个名为 Login 的组件:
export default class Login extends Component {
constructor(props) {
super(props);
this.state = {
id:'login'
}
}
render() {
return(
<KeyboardAvoidingView behavior="padding" style={style.container}>
<View style={style.logoContainer}>
<StatusBar barStyle="light-content" />
<Image style={style.logo} source={require('../../image/Octocat.png')} />
<Text style={style.logoText}> A Github app using React Native by{"\n"} Thomas Charlesworth</Text>
</View>
<View style={style.formContainer}>
<LoginForm />
</View>
</KeyboardAvoidingView>
);
}
}
还有一个登录表单组件:
export default class LoginForm extends Component {
onPressButton(){
this.props.navigator.push({
id: 'splash',
passProps: {
// Your Props
}
})
}
render() {
return(
<View style={style.container}>
<TextInput
style={style.input}
placeholder="Username"
placeholderTextColor="rgba(255,255,255,0.5)"
returnKeyType="next"
autoCapitalize="none"
autoCorrect={false}
onSubmitEditing={()=> this.passwordInput.focus()}
/>
<TextInput
style={style.input}
secureTextEntry
placeholder="Password"
placeholderTextColor="rgba(255,255,255,0.5)"
returnKeyType="go"
ref={(input) => this.passwordInput = input}
/>
<TouchableOpacity
style={style.buttonContainer}
onPress={this.onPressButton.bind(this)}
>
<Text style={style.buttonText}>
LOGIN
</Text>
</TouchableOpacity>
</View>
);
}
}
【问题讨论】:
-
这个方法你定义了吗
onPressButton?? -
我进行了编辑,请参考。我定义了一个方法是的。这停止了错误,但是当我单击按钮时,我得到:未定义不是对象(评估'this.props.navigator.push')
标签: reactjs react-native navigation native