When I click on Sign Up button I want to navigate to Sign up page but it did not work. I have imported the screens and navigated screen also to app.js file. I am getting an ReferenceError : Can’t find variable: navigation. Also I am unable to insert background image? Below is the Sign Up page.
JavaScript
x
48
48
1
import React from 'react';
2
import { StyleSheet,ImageBackground,Text, View, TextInput, TouchableOpacity } from 'react-native';
3
let bgImage='../../resources/images/bg2.png'
4
export default class LoginScreen extends React.Component {
5
state={
6
email:"",
7
password:"",
8
}
9
render(){
10
return (
11
<View style={styles.container}>
12
<Text style={styles.logo}>Trollo</Text>
13
<View style={styles.box}>
14
<View style={styles.inputView} >
15
<TextInput
16
style={styles.inputText}
17
placeholder="Email"
18
placeholderTextColor="#808080"
19
onChangeText={text => this.setState({email:text})}/>
20
</View>
21
<View style={styles.inputView} >
22
<TextInput
23
secureTextEntry
24
style={styles.inputText}
25
placeholder="Password"
26
placeholderTextColor="#808080"
27
onChangeText={text => this.setState({password:text})}/>
28
</View>
29
<TouchableOpacity style={styles.loginBtn}>
30
<Text style={styles.loginText}>SIGN IN</Text>
31
</TouchableOpacity>
32
<TouchableOpacity>
33
<Text style={styles.forgot}>Forgot Password?</Text>
34
</TouchableOpacity>
35
</View>
36
<Text style={styles.text1}>New Here?</Text>
37
<TouchableOpacity style={styles.signupBtn} onPress = {(navigation) => navigation.navigate('Sign Up')}>
38
<Text style={styles.loginText}>SIGN UP</Text>
39
</TouchableOpacity>
40
<Text style={styles.logoText}>Trollo</Text>
41
</View>
42
);
43
}
44
}
45
46
47
});
48
Advertisement
Answer
onPress
handler does not getting called with navigation
as the first parameter. That is undefined
. navigation
is a prop to your class component which is provided by stack navigator setup.
Instead of
JavaScript
1
2
1
onPress = {(navigation) => navigation.navigate('Sign Up')}
2
use
JavaScript
1
2
1
onPress = {() => this.props.navigation.navigate('Sign Up')}
2