I am trying to navigate between two screen with the help of react-navigation
. I am able to access navigate
inside the render
method as
You need to move const { navigate } = this.props.navigation;
into the onPressButton
function instead of the render
function (don't forget to bind
the function so that this
has the correct value):
export default class CreateMessageScreen extends Component {
constructor() {
super();
// need to bind `this` to access props in handler
this.onPressButton = this.onPressButton.bind(this);
}
render() {
return (
{strings.create_message}
CREATE MESSAGE
);
}
onPressButton() {
const { navigate } = this.props.navigation;
var options = {
title: strings.app_name,
content: strings.create_message,
positiveText: strings.OK,
onPositive: () => navigate("DashboardScreen")
};
var dialog = new DialogAndroid();
dialog.set(options);
dialog.show();
}
}