<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: popoola abiodun </title>
    <description>The latest articles on DEV Community by popoola abiodun  (@popoolaabiodun).</description>
    <link>https://dev.to/popoolaabiodun</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1105687%2F59c5050c-5b9e-4e80-92fe-a86b37864017.jpg</url>
      <title>DEV Community: popoola abiodun </title>
      <link>https://dev.to/popoolaabiodun</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/popoolaabiodun"/>
    <language>en</language>
    <item>
      <title>Guide to React Native Screen Navigation</title>
      <dc:creator>popoola abiodun </dc:creator>
      <pubDate>Thu, 22 Jun 2023 14:13:21 +0000</pubDate>
      <link>https://dev.to/popoolaabiodun/guide-to-react-native-screen-navigation-54k7</link>
      <guid>https://dev.to/popoolaabiodun/guide-to-react-native-screen-navigation-54k7</guid>
      <description>&lt;p&gt;As a mobile app developer, designing a user interface with multiple screens and functionalities that enable easy navigation throughout the application is essential for creating a seamless user experience.&lt;br&gt;
There are several libraries used for screen navigation in React Native applications. Still, React-Native-Navigation is one of the most common because it is well-maintained, easy to learn, and has a large community.&lt;br&gt;
In this tutorial, we will learn about React Native navigation and how to dynamically navigate our application from one screen to another.&lt;/p&gt;
&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;To follow this tutorial, you should have the following prerequisites in place:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic knowledge of React Native programming.&lt;/li&gt;
&lt;li&gt;You should have Node.js and npm installed on your computer.&lt;/li&gt;
&lt;li&gt;Additionally, you should have set up your emulator already.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  What is React Native Navigation
&lt;/h2&gt;

&lt;p&gt;React-Native-Navigation is a popular screen navigation library for React Native applications created and maintained by Wix. It provides a smooth and seamless navigation experience for iOS and Android platforms, with a native look and feels.&lt;br&gt;
One of the benefits of using React-Native-Navigation is its performance, which makes it a good choice for applications that require a fast and responsive navigation system. It supports various navigation options, such as stack navigation, bottom tab navigation, and side menu navigation.&lt;/p&gt;
&lt;h2&gt;
  
  
  Creating React Native App
&lt;/h2&gt;

&lt;p&gt;To get started, let's create a new React Native app using the Expo tools, which allow us to install the application without configuring Xcode or Android Studio. To create the React Native app, run the following command in your terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-expo-app ReactNavigationApp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After creating the project, open it in your code editor. Using the VS Code editor, you can open the project using the command below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ReactNavigationDemo
code .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using React Router Native
&lt;/h2&gt;

&lt;p&gt;To use React Router Native in the application, we first need to install the dependency into the application. Run the following commands to install the React Router Native package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @react-navigation/native
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's explore some major patterns and examples of using the React Native navigation library in our application.&lt;br&gt;
&lt;strong&gt;Stack Navigator&lt;/strong&gt;&lt;br&gt;
Stack Navigator provides a way to switch between different screens or pages within a mobile app. It works by stacking screens on top of each other, and when the user goes back, the top screen is removed from the Stack.&lt;br&gt;
Using the commands below, we need to install react-native-screens and react-native-safe-area-context to use Stack Navigator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx expo install react-native-screens react-native-safe-area-context
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s start by creating a &lt;strong&gt;components&lt;/strong&gt; folder in the project root directory. Then, inside the components folder, &lt;strong&gt;create HomeScreen.js&lt;/strong&gt; and &lt;strong&gt;ProfileScreen.js&lt;/strong&gt;.&lt;br&gt;
Next, to create the home screen, open the HomeScreen.js file and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // Homescreen.js
    import React from "react";
    import { Button, View, Text } from "react-native";
    export default function HomeScreen({ navigation }) {
      return (
        &amp;lt;View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}&amp;gt;
          &amp;lt;Text&amp;gt;Home Screen&amp;lt;/Text&amp;gt;
          &amp;lt;Button
            title="Go to Profile"
            onPress={() =&amp;gt; navigation.navigate("Profile")}
          /&amp;gt;
        &amp;lt;/View&amp;gt;
      );
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above, the functional component &lt;strong&gt;HomeScreen&lt;/strong&gt; takes &lt;strong&gt;'navigation'&lt;/strong&gt; as a parameter, which is used to pass in the &lt;strong&gt;'navigation'&lt;/strong&gt; object. This object provides access to the navigation methods used to move between screens in the app.&lt;br&gt;
Also, we created a button with an &lt;strong&gt;onPress&lt;/strong&gt; property. When the user presses the button, the &lt;strong&gt;navigation.navigate("Profile")&lt;/strong&gt; method is triggered, causing the screen to transition to the Profile screen.&lt;br&gt;
Now, open &lt;strong&gt;ProfileScreen.js&lt;/strong&gt; and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // ProfileScreen.js
    import React from "react";
    import { View, Text } from "react-native";
    export default function AboutScreen() {
      return (
        &amp;lt;View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}&amp;gt;
          &amp;lt;Text&amp;gt;Profile Screen&amp;lt;/Text&amp;gt;
        &amp;lt;/View&amp;gt;
      );
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need to import both &lt;strong&gt;NavigationContainer&lt;/strong&gt; and &lt;strong&gt;createNativeStackNavigator&lt;/strong&gt; in the &lt;strong&gt;app.js&lt;/strong&gt; file. From your project root directory, open the app.js file and add the following code to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // App.js
    import * as React from "react";
    import { NavigationContainer } from "@react-navigation/native";
    import { createNativeStackNavigator } from "@react-navigation/native-stack";
    import HomeScreen from "./components/HomeScreen";
    import ProfileScreen from "./components/ProfileScreen";
    const Stack = createNativeStackNavigator();
    export default function App() {
      return (
        &amp;lt;NavigationContainer&amp;gt;
          &amp;lt;Stack.Navigator&amp;gt;
            &amp;lt;Stack.Screen name="Home" component={HomeScreen} /&amp;gt;
            &amp;lt;Stack.Screen name="Profile" component={ProfileScreen} /&amp;gt;
          &amp;lt;/Stack.Navigator&amp;gt;
        &amp;lt;/NavigationContainer&amp;gt;
      );
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above creates a Stack object using the &lt;strong&gt;createNativeStackNavigator&lt;/strong&gt; function and uses it to define the navigator for the app. The navigator contains two screens, Home and Profile, defined using the &lt;strong&gt;Stack.Screen&lt;/strong&gt; component. The name property of each screen specifies its unique identifier, while the component property specifies the React component to render when the screen is displayed.&lt;br&gt;
To start the application, run the following command on your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    npx expo start
    #  press i to start on IOS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above command will start the iOS emulator, and you should have the following output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IAVKTgBx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://lh4.googleusercontent.com/boFLGUirSw3176eg_wW-bjbVkGL8xnr40ApITxPb03stOIQT0fehGTzGZSmQgJRY6UETfAU73_O_SbVr2JAV4Qipjtr6pp276yEfwvwPq7mQfAxpZridb7dYb7HaO1BX5xA_t8uFg3XanLoHEpKqejI" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IAVKTgBx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://lh4.googleusercontent.com/boFLGUirSw3176eg_wW-bjbVkGL8xnr40ApITxPb03stOIQT0fehGTzGZSmQgJRY6UETfAU73_O_SbVr2JAV4Qipjtr6pp276yEfwvwPq7mQfAxpZridb7dYb7HaO1BX5xA_t8uFg3XanLoHEpKqejI" alt="" width="368" height="685"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tab Navigation&lt;/strong&gt;&lt;br&gt;
Tab Navigation allows users to switch between screens in a React Native app by tapping on tabs at the bottom or top of the screen. Each tab represents a different section of the app, and tapping on a tab takes the user to the corresponding screen for that section.&lt;br&gt;
To use the bottom tab navigation, we must first install createBottomTabNavigator in our application using the below command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i @react-navigation/bottom-tabs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, in the app.js file, we need to import createBottomTabNavigator and replace the code in the file with the code below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // App.js
    import * as React from "react";
    import { NavigationContainer } from "@react-navigation/native";
    import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
    import HomeScreen from "./components/HomeScreen";
    import ProfileScreen from "./components/ProfileScreen";
    const Tab = createBottomTabNavigator();
    export default function App() {
      return (
        &amp;lt;NavigationContainer&amp;gt;
          &amp;lt;Tab.Navigator&amp;gt;
            &amp;lt;Tab.Screen name="Home" component={HomeScreen} /&amp;gt;
            &amp;lt;Tab.Screen name="Profile" component={ProfileScreen} /&amp;gt;
          &amp;lt;/Tab.Navigator&amp;gt;
        &amp;lt;/NavigationContainer&amp;gt;
      );
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above, we create a Tab object using the &lt;strong&gt;createBottomTabNavigator&lt;/strong&gt; function and use it to define the tab navigator for the app. The navigator contains two tabs, &lt;strong&gt;'Home'&lt;/strong&gt; and &lt;strong&gt;'Profile'&lt;/strong&gt;, defined using the &lt;strong&gt;Tab.Screen&lt;/strong&gt; component. The name property of each tab specifies its unique identifier, while the component property specifies the React component to render when the tab is selected.&lt;br&gt;
Save the code and refresh your emulator. You should have the following output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L_8CHS6s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://lh3.googleusercontent.com/SXNt_ks-t61nCvuoPKK2fQRfr6CRIeXxzoOz5E49jyierKa2Sv3rD4EG1KpyJ62IXNX9bqgUwzHoadPu9P3_rT_bmn9Fe-U540RQ6ppm31Z7egFgZpRkKWdv5mk2s9FTozSYgRaZxypazxgIZBSpfW0" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L_8CHS6s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://lh3.googleusercontent.com/SXNt_ks-t61nCvuoPKK2fQRfr6CRIeXxzoOz5E49jyierKa2Sv3rD4EG1KpyJ62IXNX9bqgUwzHoadPu9P3_rT_bmn9Fe-U540RQ6ppm31Z7egFgZpRkKWdv5mk2s9FTozSYgRaZxypazxgIZBSpfW0" alt="" width="366" height="682"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Drawer Navigation&lt;/strong&gt;&lt;br&gt;
Drawer navigation is a type of navigation component in React Native that allows users to access different screens within an app by opening a drawer menu that slides in from the side of the screen.&lt;br&gt;
To use the drawer navigation, we need to install the following dependencies using the command below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    npm install @react-navigation/drawer
    npx expo install react-native-gesture-handler react-native-reanimated

Next, to use the drawer navigation effect, open the app.js file and replace its code with the following code:

    // App.js
    import * as React from "react";
    import { NavigationContainer } from "@react-navigation/native";
    import { createDrawerNavigator } from '@react-navigation/drawer';
    import HomeScreen from './HomeScreen';
    import ProfileScreen from './ProfileScreen';
    const Drawer = createDrawerNavigator();
    function App() {
      return (
        &amp;lt;NavigationContainer&amp;gt;
          &amp;lt;Drawer.Navigator&amp;gt;
            &amp;lt;Drawer.Screen name="Home" component={HomeScreen} /&amp;gt;
            &amp;lt;Drawer.Screen name="Profile" component={ProfileScreen} /&amp;gt;
          &amp;lt;/Drawer.Navigator&amp;gt;
        &amp;lt;NavigationContainer&amp;gt;
      );
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, we create a Drawer object using the createDrawerNavigator function and use it to define the drawer navigator for the app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Passing parameters in Screen Navigation
&lt;/h2&gt;

&lt;p&gt;Sometimes we must pass data like a user ID from one screen to another as the user navigates through the application. In React Native Navigation, sending data between screens is pretty simple.&lt;br&gt;
To pass data, we’ll add route parameters to the navigation. Use the navigate function as shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    onPress={() =&amp;gt; navigation.navigate("About",{ userID:12 })}
    Next, we can get the data in the ProfileScreen using the following code:
    // Profilescreen.js
    import React, { Component } from "react";
    import { Button, View, Text } from "react-native";
    export default function AboutScreen({ route }) {
    const { userID } = route;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;With React Native Navigation, we can implement screen navigation with different effects to swap between screens. In this article, we learned how to implement screen navigation in a React Native app using React Native Navigator.&lt;br&gt;
I'm just getting into React Native development and found this library interesting. I hope the tutorial is helpful. You can learn more about React Native Navigation from their official documentation.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
