I'm trying to navigate inside the function _login rather than inline. In the function this.props.navigation is undefined. What's wrong there?
import React from 'react';
import { StyleSheet, Form, View, Text } from 'react-native';
import { StackNavigator } from 'react-navigation';
import { Button, FormValidationMessage, FormLabel, FormInput } from 'react-native-elements';
import { AgendaScreen } from './AgendaScreen';
class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Please sign in',
};
render() {
return (
<View style={styles.container}>
<FormLabel>Username</FormLabel>
<FormInput onChangeText={this.inputChanged} />
<FormValidationMessage>{'This field is required'}</FormValidationMessage>
<FormLabel>Password</FormLabel>
<FormInput secureTextEntry={true} onChangeText={this.inputChanged} />
<FormValidationMessage>{'This field is required'}</FormValidationMessage>
<Button raised onPress={this._login} title="Sign in" />
</View>
);
}
inputChanged() {
console.log('adfasdf');
}
_login() {
this.props.navigation.navigate('Agenda');
console.log('Logging in');
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff'
}
});
export default StackNavigator({
Home: HomeScreen,
Agenda: AgendaScreen
});