# Basic ReactNavigation Example App and Tutorial
This is a simple 3-page application that demonstrates the basic usage of [React Navigation](https://reactnavigation.org/) as a navigation tool. It is extremely easy to understand. This step-by-step tutorial will take you through the basic concepts. We are using [NativeBase](https://nativebase.io/) as the UI library to design our pages.
# Find full code [here](https://github.com/GeekyAnts/native-base-react-navigation-stack-navigator)

## Aim
We are creating a 3-page application with buttons on each page that takes us to the other page onPress.
## Installation
1. **Create React Native App**: Use [CRNA](https://github.com/react-community/create-react-native-app) tool to create an App like this
$ npm install -g create-react-native-app
$ create-react-native-app my-app
$ cd my-app/
$ npm start
2. **Installing Libraries**
With a React Native project SetUp, We can now install all required Libraries as follows.
a. **React Navigation**
Do this
npm install --save react-navigation
b. **NativeBase**
npm install native-base --save
**Configure all dependencies by running the following command**
react-native link
By the end of Installation, your package.json file should look something like this.

## Lets Play
With our basic project setup we can now start building our App.
Make a folder at the project root by the name of src. Inside this folder we make 3 folders ChatScreen HomeScreen ProfileScreen.
## HomeScreen
This is going to be the first landing screen of out App. We are going to implement the navigation logic here.
For our purpose here, we have used **DrawerNavigator** for navigation through the entire app.
Further screens will have **nested navigators** in them.
Go ahead and add the following file in your project.
**Code HomeScreen/HomeScreen.js**
import React from "react";
import { StatusBar } from "react-native";
import {
Button,
Text,
Container,
Card,
CardItem,
Body,
Content,
Header,
Title,
Left,
Icon,
Right
} from "native-base";
export default class HomeScreen extends React.Component {
render() {
return (
<Container>
<Header>
<Left>
<Button
transparent
onPress={() => this.props.navigation.navigate("DrawerOpen")}>
<Icon name="menu" />
</Button>
</Left>
<Body>
<Title>HomeScreen</Title>
</Body>
<Right />
</Header>
<Content padder>
<Card>
<CardItem>
<Body>
<Text>Chat App to talk some awesome people!</Text>
</Body>
</CardItem>
</Card>
<Button
full
rounded
dark
style={{ marginTop: 10 }}
onPress={() => this.props.navigation.navigate("Chat")}>
<Text>Chat With People</Text>
</Button>
<Button
full
rounded
primary
style={{ marginTop: 10 }}
onPress={() => this.props.navigation.navigate("Profile")}>
<Text>Goto Profiles</Text>
</Button>
</Content>
</Container>
);
}
}
openDrawer or navigate to other components.
2. The **navigation** object is available as a prop to us as we declare this component inside a *DrawerNavigator* in index.js. import React, { Component } from "react";
import HomeScreen from "./HomeScreen.js";
import MainScreenNavigator from "../ChatScreen/index.js";
import Profile from "../ProfileScreen/index.js";
import SideBar from "../SideBar/SideBar.js";
import { DrawerNavigator } from "react-navigation";
const HomeScreenRouter = DrawerNavigator(
{
Home: { screen: HomeScreen },
Chat: { screen: MainScreenNavigator },
Profile: { screen: Profile }
},
{
contentComponent: props => <SideBar {...props} />
}
);
export default HomeScreenRouter;
this.props.navigation since we passed the props in the HomeScreen component. import React from "react";
import { AppRegistry, Image, StatusBar } from "react-native";
import {
Button,
Text,
Container,
List,
ListItem,
Content,
Icon
} from "native-base";
const routes = ["Home", "Chat", "Profile"];
export default class SideBar extends React.Component {
render() {
return (
<Container>
<Content>
<Image
source={{
uri: "https://github.com/GeekyAnts/NativeBase-KitchenSink/raw/react-navigation/img/drawer-cover.png"
}}
style={{
height: 120,
alignSelf: "stretch",
justifyContent: "center",
alignItems: "center"
}}>
<Image
square
style={{ height: 80, width: 70 }}
source={{
uri: "https://github.com/GeekyAnts/NativeBase-KitchenSink/raw/react-navigation/img/logo.png"
}}
/>
</Image>
<List
dataArray={routes}
renderRow={data => {
return (
<ListItem
button
onPress={() => this.props.navigation.navigate(data)}>
<Text>{data}</Text>
</ListItem>
);
}}
/>
</Content>
</Container>
);
}
}
import React, { Component } from "react";
import LucyChat from "./LucyChat.js";
import JadeChat from "./JadeChat.js";
import NineChat from "./NineChat.js";
import { TabNavigator } from "react-navigation";
import {
Button,
Text,
Icon,
Item,
Footer,
FooterTab,
Label
} from "native-base";
export default (MainScreenNavigator = TabNavigator(
{
LucyChat: { screen: LucyChat },
JadeChat: { screen: JadeChat },
NineChat: { screen: NineChat }
},
{
tabBarPosition: "bottom",
tabBarComponent: props => {
return (
<Footer>
<FooterTab>
<Button
vertical
active={props.navigationState.index === 0}
onPress={() => props.navigation.navigate("LucyChat")}>
<Icon name="bowtie" />
<Text>Lucy</Text>
</Button>
<Button
vertical
active={props.navigationState.index === 1}
onPress={() => props.navigation.navigate("JadeChat")}>
<Icon name="briefcase" />
<Text>Nine</Text>
</Button>
<Button
vertical
active={props.navigationState.index === 2}
onPress={() => props.navigation.navigate("NineChat")}>
<Icon name="headset" />
<Text>Jade</Text>
</Button>
</FooterTab>
</Footer>
);
}
}
));
import React from "react";
import { AppRegistry, View, StatusBar } from "react-native";
import {
Button,
Text,
Container,
Card,
CardItem,
Body,
Content,
Header,
Left,
Right,
Icon,
Title,
Input,
InputGroup,
Item,
Tab,
Tabs,
Footer,
FooterTab,
Label
} from "native-base";
import HomeScreen from "../HomeScreen";
export default class LucyChat extends React.Component {
render() {
const { navigate } = this.props.navigation;
return (
<Container>
<Header>
<Left>
<Button
transparent
onPress={() => this.props.navigation.navigate("DrawerOpen")}>
<Icon name="menu" />
</Button>
</Left>
<Body>
<Title>Lucy Chat</Title>
</Body>
<Right />
</Header>
<Content padder>
<Item floatingLabel style={{ marginTop: 20 }}>
<Label>Lucy Chat</Label>
<Input />
</Item>
<Button
rounded
danger
style={{ marginTop: 20, alignSelf: "center" }}
onPress={() => navigate("Profile")}>
<Text>Goto Lucy Profile</Text>
</Button>
</Content>
</Container>
);
}
}
import React, { Component } from "react";
import Profile from "./Profile.js";
import EditScreenOne from "./EditScreenOne.js";
import EditScreenTwo from "./EditScreenTwo.js";
import { StackNavigator } from "react-navigation";
export default (DrawNav = StackNavigator({
Profile: { screen: Profile },
EditScreenOne: { screen: EditScreenOne },
EditScreenTwo: { screen: EditScreenTwo }
}));
import React from "react";
import { AppRegistry, Alert } from "react-native";
import {
Text,
Container,
Card,
CardItem,
Body,
Content,
Header,
Left,
Right,
Icon,
Title,
Button,
H1
} from "native-base";
import { StackNavigator } from "react-navigation";
import EditScreenOne from "./EditScreenOne.js";
import EditScreenTwo from "./EditScreenTwo.js";
export default class Profile extends React.Component {
componentDidMount() {
Alert.alert("No Users Found", "Oops, Looks like you are not signed in");
}
render() {
return (
<Container>
<Content padder>
<Card>
<CardItem>
<Icon active name="paper-plane" />
<Text>Show User profiles here</Text>
<Right>
<Icon name="close" />
</Right>
</CardItem>
</Card>
<Button
full
rounded
primary
style={{ marginTop: 10 }}
onPress={() => this.props.navigation.navigate("EditScreenOne")}>
<Text>Goto EditScreen One</Text>
</Button>
</Content>
</Container>
);
}
}
Profile.navigationOptions = ({ navigation }) => ({
header: (
<Header>
<Left>
<Button transparent onPress={() => navigation.navigate("DrawerOpen")}>
<Icon name="menu" />
</Button>
</Left>
<Body>
<Title>Profile</Title>
</Body>
<Right />
</Header>
)
});
import React from "react";
import { AppRegistry, Alert } from "react-native";
import {
Text,
Container,
Card,
CardItem,
Body,
Content,
Header,
Left,
Right,
Icon,
Title,
Button,
H1
} from "native-base";
export default class EditScreenOne extends React.Component {
static navigationOptions = ({ navigation }) => ({
header: (
<Header>
<Left>
<Button transparent onPress={() => navigation.goBack()}>
<Icon name="arrow-back" />
</Button>
</Left>
<Body>
<Title>EditScreenOne</Title>
</Body>
<Right />
</Header>
)
});
render() {
return (
<Container>
<Content padder>
<Card>
<CardItem>
<Icon active name="paper-plane" />
<Text>Edit Screen 1</Text>
<Right>
<Icon name="close" />
</Right>
</CardItem>
</Card>
<Button
full
rounded
primary
style={{ marginTop: 10 }}
onPress={() => this.props.navigation.navigate("EditScreenTwo")}>
<Text>Goto EditScreenTwo</Text>
</Button>
</Content>
</Container>
);
}
}
import React, { Component } from "react";
import { View } from "react-native";
import { Container, Content, Picker, Button, Text } from "native-base";
import Expo from "expo";
import HomeScreen from "./src/HomeScreen/index.js";
export default class AwesomeApp extends Component {
constructor() {
super();
this.state = {
isReady: false
};
}
async componentWillMount() {
await Expo.Font.loadAsync({
Roboto: require("native-base/Fonts/Roboto.ttf"),
Roboto_medium: require("native-base/Fonts/Roboto_medium.ttf"),
Ionicons: require("native-base/Fonts/Ionicons.ttf")
});
this.setState({ isReady: true });
}
render() {
if (!this.state.isReady) {
return <Expo.AppLoading />;
}
return <HomeScreen />;
}
}