visit
So, let’s get started!
"react-native-gesture-handler": "^1.4.1",
"react-native-reanimated": "^1.3.0",
"react-navigation": "^4.0.10",
"react-navigation-tabs": "^2.5.5"
pod install
Now, we need to run the project in our iOS emulator by using the following code snippet:react-native run-ios
Note that: The emulator may need to run prior to running the app in the emulator.The code for the Profile screen in provided in the code snippet below. We need to copy the code given below and paste it to
Profile.js
file.import React, {Component} from 'react';
import {View, Text, StyleSheet} from 'react-native';
class Profile extends Component {
render() {
return (
<View style={styles.container}>
<Text>Profile</Text>
</View>
);
}
}
export default Profile;
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
});
Now, we need to do the same for all the other screens. That is, copy the code from above code snippet of the Profile screen and then paste it to other remaining for screen files.
We need to remember to change the class name for each screen matching their respective file names.
For example:Explore.js
, we need to edit the class name to Explore.Saved.js
, we need to edit the class name to Saved.Trip.js
, we need to edit the class name to Edit.Inbox.js
, we need to edit the class name to Inbox.This step is very important because we are going to configure the navigations for our app. Here, we are going to use
createBottomTabNavigator
method provided by react-navigation-tabs. Hence, this method enables us to set up a bottom tab menu with all the screens that we created earlier. Thus, we need to open the App.js file and then import all the packages and screens that are required to configure our bottom
TabNavigator
as shown in the code snippet below:import {createAppContainer} from 'react-navigation';
import {createBottomTabNavigator} from 'react-navigation-tabs';
import Explore from './screens/Explore';
import Saved from './screens/Saved';
import Inbox from './screens/Inbox';
import Trip from './screens/Trip';
const TabNavigator = createBottomTabNavigator({
Explore: {
screen: Explore,
},
Saved: {
screen: Saved,
},
Trip: {
screen: Trip,
},
Inbox: {
screen: Inbox,
},
Profile: {
screen: Inbox,
},
});
export default createAppContainer(TabNavigator);
Here, we use Buttom Tab navigator from react-navigation-tabs and map screens to the menu. Then, we use the App container imported from react-navigation package to wrap our
TabNavigator
with all the screens.Hence, we get the following result in our emulator screen:In this step, we are going to add the Icons to our bottom tab menu buttons. For that, we need to install a package that provides us with beautiful icons. So, the package we use here is react-native-vector-icons which provides us with icons from different icon providers like Ionicons, FontAwesome, Material Design, etc.
To add the package to our project, we need to run the following command in our project command prompt:yarn add react-native-vector-icons
And one more important thing is that we need to add Font from
node_modules
to the XCode project manually. For the iOS platform, we need to follow this instruction from and . The addition of Font to Xcode is shown in the screenshot below:Then, we need to import the react-native-vector-icons package into our App.js file with Ionicons as the required icon package as shown in the code snippet below:
import Icon from 'react-native-vector-icons/Ionicons'
Then, we need to add the icons to our botton menu tab buttons by using
navigationOptions
object which will help us configure the navigator options. In the navigationOptions
object, we can set the tabBarLabel
and tabBarIcon
as shown in the code snippet below:const TabNavigator = createBottomTabNavigator(
{
Explore: {
screen: Explore,
navigationOptions: {
tabBarLabel: "EXPLORE",
tabBarIcon: ({ tintColor }) => (
<Icon name="ios-search" color={tintColor} size={24} />
)
}
},
Saved: {
screen: Saved,
navigationOptions: {
tabBarLabel: "SAVED",
tabBarIcon: ({ tintColor }) => (
<Icon name="ios-heart" color={tintColor} size={24} />
)
}
},
Trip: {
screen: Trip,
navigationOptions: {
tabBarLabel: "TRIP",
tabBarIcon: ({ tintColor }) => (
<Image
source={require("./images/airbnb.png")}
style={{ height: 24, width: 24, tintColor: tintColor }}
/>
)
}
},
Inbox: {
screen: Inbox,
navigationOptions: {
tabBarLabel: "INBOX",
tabBarIcon: ({ tintColor }) => (
<Icon name="ios-chatboxes" color={tintColor} size={24} />
)
}
},
Profile: {
screen: Inbox,
navigationOptions: {
tabBarLabel: "PROFILE",
tabBarIcon: ({ tintColor }) => (
<Icon name="ios-person" color={tintColor} size={24} />
)
}
}
},
tintColor
is color that we use to define the color for the menu. Here, we are going to set the activeTintColor
and inactiveTintColor
.Finally, we need to add some extra styles to the menu and configure it as a second parameter to
createBottomTabNavigator
as shown in the code snippet below:,
{
tabBarOptions: {
activeTintColor: "red",
inactiveTintColor: "grey",
style: {
backgroundColor: "white",
borderTopWidth: 0,
shadowOffset: { width: 5, height: 3 },
shadowColor: "black",
shadowOpacity: 0.5,
elevation: 5
}
}
}
Then, we are going to use
TextInput
component and Icon component to create the search bar with a search icon on the left side. Then, we need to wrap the Icon and TextInput
components with a View component containing required styles. Moreover, This View component must be wrapped with another View component and then again wrapped with
SafeAreaView
component in order to make the Search bar visible and well below the device status bar. The required code and the styles in order to implement the search bar are provided in the code snippet below:import React, { Component } from "react";
import { View, TextInput, SafeAreaView } from "react-native";
import Icon from "react-native-vector-icons/Ionicons";
class Explore extends Component {
render() {
return (
<SafeAreaView style={{ flex: 1 }}>
<View style={{ flex: 1 }}>
<View
style={{
backgroundColor: "white",
height: 80,
borderBottomWidth: 1,
borderBottomColor: "#dddddd"
}}
>
<Icon name="ios-search" size={20} style={{ marginRight: 10 }} />
<TextInput />
</View>
</View>
</SafeAreaView>
);
}
}
export default Explore;
As we can see, the search bar the top looks out of its place and doesn’t look appealing at all. So, we need to add some styles to the search
TextInput
component and to the View component wrapping the icon and search input in order to make it look more appealing. The code to do this provided in the code snippet below:<View
style={{
backgroundColor: "white",
height: 80,
borderBottomWidth: 1,
borderBottomColor: "#dddddd"
}}
>
<View
style={{
flexDirection: "row",
padding: 10,
backgroundColor: "white",
marginHorizontal: 20,
shadowOffset: { width: 0, height: 0 },
shadowColor: "black",
shadowOpacity: 0.2
}}
>
<Icon name="ios-search" size={20} style={{ marginRight: 10 }} />
<TextInput
underlineColorAndroid="transparent"
placeholder="Try ChiangMai"
placeholderTextColor="grey"
style={{ flex: 1, fontWeight: "700", backgroundColor: "white" }}
/>
</View>
</View>
This is the first part of our Airbnb clone tutorial series. In this post, we learned how to use
BottomTabNavigator
provided by react-navigation and set up the bottom tab menu. We also got step by step guide on how to set up a search bar at the top. We also learned how to set up different packages that help us create an app that mimics the Airbnb app. In the next part of this tutorial series, we will work on Horizontal ScrollView. So, Stay Tuned!!