I've been trying to be able to change screens by clicking on the Image within the code but it isn't working.
I've tried defining Push, navigate and other props but it always says that undefined is not an object and show the prop.
import React from 'react';
import { AppRegistry, StyleSheet, View, Image, TouchableOpacity, Button } from "react-native";
import { widthPercentageToDP as wp, heightPercentageToDP as hp } from 'react-native-responsive-screen'
import { StackNavigator, createStackNavigator, createAppContainer } from 'react-navigation';
import Screen from './Screen'
export default class Additional extends React.Component {
render(){
const { navigate } = this.props.navigation;
return (
<View style={styles.container}>
<TouchableOpacity onPress={() =>
navigate("Screen")}
>
<Image
style={{
tintColor: "#9B9B9B", height: 56, width: 56,
position: 'absolute', alignSelf: 'center', top: wp('-84.0%'), left: wp('5%'),
}}
source={require("../Icons/XButton.png")}
/>
</TouchableOpacity>
</View>
)
}
}
const AppNavigator = createStackNavigator({
Home: {screen: Home},
Screen: {screen: Screen},
}, {
initialRouteName: 'Home',
});
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
}
})
Parent:
i
Grandparent:
Because
Additional
is not increateStackNavigator
screens list. So,this.props.navigation
isundefined
. To cover this, first, you have toexport default AppNavigator
, and in another component (for exampleAdditional
) you must usewithNavigation
method.In root component:
In Additional component: