Complete React Native Tutorial #10 - Tab Bar Icons

Net Ninja · Beginner ·🔧 Backend Engineering ·1y ago
Skills: React90%

Key Takeaways

This video tutorial demonstrates how to add custom tab bar icons to a React Native application using the Expo Vector Icons package. The tutorial covers installing the package, importing the IonIcons component, and dynamically setting the icon and color based on the tab's focus state.

Full Transcript

All right, then. So, in the last lesson, we put together this tabbed navigation, and it all works. I can navigate between the different pages by clicking on the tabs. And the colors work as well. We've applied different theme colors so that it works for light and dark. But at the minute, these icons look atrocious, the little triangles. So, instead, I would like to use a custom icon for each one. like maybe a little person for the profile, a book for the books, and I don't know a square with a pencil sticking out of it for the create tab. And we can do that really easily. So, the first thing we have to do is install a package for um this project, which is an icon package. Now, if you started the project using the default uh template for creating a React Native application, I think it comes bundled with this um icon package. However, if you didn't, you need to install it manually. Now to do that you can cancel out of the current process and you can say npx install and then it's at expo slve vector- icons. Now I've already done that before this lesson so I'm not going to press enter but if you press enter it's going to install it for you and then you can start up the server again. All right so once you've got that up and running we can now add the icons to these different tabs. Now before we do that, we need to import a component from the icon package. Now I'm going to be using a component called ion icons. I don't know how to fully pronounce that. Is it ion icons or ion icons? Either way, we're importing this component from at expo/vector icons which we just installed. And now we can use that down here to output a different icon. So if we come to the profile tab first and then to the options we can add another property right here called tab bar icon. Now the value of this is going to be a function which returns inside parentheses a template and that template is just going to be that component ion icon or ion icons rather and then this is self-closing but we do need to pass a few props to this. The first prop is going to be the size of the icon. So, I'm going to say that will be 24 pixels. You can play around with the size if you want. The next one is the name. Now, the name decides which um icon we want to use. Now, there's a big list of them here. I'm going to go for one called person. And then I'm going to save this. Now, when we save it, we should see now that icon appear over here. It's black at the moment. We are going to give it a color, but at least we see it. And it's filled in. All right. Now, what I'd like to do actually is use one called person outline, I think it is. If I save that, we should see something different after a second. Yeah, we see the outline of the person instead. So, I'd like to use that when it's not focused, the tab. But when it is focused, I'd like to use the person. So, how do we do that? Well, this value then has to be dynamic. And we need to evaluate whether it's focused or not, this particular tab. Now, as an argument to this function up here, we can dstructure the um focused property and this is going to be true or false. Now, if this tab is focused, it's going to be true. If it's not, it's false. So, we can use that then to dynamically output a different icon name. So, I could say focused question mark. And we're going to use a turnary to do this, by the way. And then if that's true, I want to use the person. And if it's not true, I want to use the person outline. All right. So if I save this now, you can see currently it's focused. But if I go away from it, then it becomes the outline. And then it becomes filled again when we focus it. All right. Cool. So now I want to do the color. And the color is going to come from the theme that we already have up here. Remember, it could be the light or dark theme, but we're going to use a theme color. And the theme color we're going to use are the same colors as down here. So if it's focused, we're going to use this one. If it's not focused, we're going to use this one. So let me just copy this in preparation for the focus state. And again, we'll use a turn array. So we can say focused. And then oops, spell it correctly. Focused. And then if it is focused, we will use this color, the icon color focused. If not, then it's going to be theme dot icon color. All right. So now if we save this, we can see it's white when it's focused. If I navigate away, it becomes kind of like a gray color. So that's nice, right? Okay. So all we need to do now is copy this thing and paste it down in each one of these. So first of all, we need the tab bar icon property which is a function where we dstructure the focused property. And then inside this function, we need to return that component again. So this time we don't want person. We want an icon called books. Is it books or book? I think it's just book. And then book outlined. Let's try it out. Oh yeah, we get the book. Awesome. All right. So finally, we need to do the same thing down here. We need the tab bar icon, which is a function. we destructure the focus property and then in here we can just return the template. All right. So let's paste it in again. And this time we want instead of person I think it's just called create. Let's have a look. Create and then create outline. Save that. Yep. All right. That looks good. So now we have all our icons in the tabs. Awesome.

Original Description

In this complete React Native tutorial, you'll learn how to develop native apps from the ground up, using React Native and Expo. You'll learn about native components, routing, navigation, styling, authentication and a lot more too. 🔥🥷🏼 Get instant access to ALL premium courses on NetNinja.dev: https://netninja.dev/ 🔥🥷🏼 Get instant access to This Course on NetNinja.dev: https://netninja.dev/p/complete-react-native 🔗👇 Sign up to Appwrite & Get $50 Free Credit: https://apwr.dev/netninja050 📂🥷🏼 Access the course files on GitHub: https://github.com/iamshaunjp/Complete-React-Native-Tutorial 🧠🥷🏼 React Course: https://netninja.dev/p/build-websites-with-react-firebase 🧠🥷🏼 React Context and Hooks Course: https://www.youtube.com/watch?v=6RhOzQciVwI&list=PL4cUxeGkcC9hNokByJilPg5g9m2APUePI 🔗👇 Install Node.js: https://nodejs.org/en 🔗👇 React Native Docs: https://reactnative.dev/docs/getting-started 🔗👇 Expo Docs: https://docs.expo.dev/ 🔗👇 Appwrite docs: https://appwrite.io/docs
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Net Ninja · Net Ninja · 0 of 60

← Previous Next →
1 Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
2 Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
3 Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
4 GraphQL Tutorial #1 - Introduction to GraphQL
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
5 GraphQL Tutorial #2 - A Birdseye View of GraphQL
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
6 GraphQL Tutorial #3 - Project (stack) Overview
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
7 GraphQL Tutorial #4 - Making Queries (front-end preview)
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
8 GraphQL Tutorial #5 - Express App Setup
GraphQL Tutorial #5 - Express App Setup
Net Ninja
9 GraphQL Tutorial #6 - Setting up GraphQL
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
10 GraphQL Tutorial #7 - GraphQL Schema
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
11 GraphQL Tutorial #8 - Root Query
GraphQL Tutorial #8 - Root Query
Net Ninja
12 GraphQL Tutorial #9 - The Resolve Function
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
13 GraphQL Tutorial #10 - Testing Queries in Graphiql
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
14 GraphQL Tutorial #11 - GraphQL ID Type
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
15 GraphQL Tutorial #12 - Author Type
GraphQL Tutorial #12 - Author Type
Net Ninja
16 GraphQL Tutorial #13 - Type Relations
GraphQL Tutorial #13 - Type Relations
Net Ninja
17 GraphQL Tutorial #14 - GraphQL Lists
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
18 GraphQL Tutorial #15 - More on Root Queries
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
19 GraphQL Tutorial #16 - Connecting to mLab
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
20 GraphQL Tutorial #17 - Mongoose Models
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
21 GraphQL Tutorial #18 - Mutations
GraphQL Tutorial #18 - Mutations
Net Ninja
22 GraphQL Tutorial #19 - More on Mutations
GraphQL Tutorial #19 - More on Mutations
Net Ninja
23 GraphQL Tutorial #20 - Updating the Resolve Functions
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
24 GraphQL Tutorial #21 - GraphQL NonNull
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
25 GraphQL Tutorial #22 - Adding a Front-end
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
26 GraphQL Tutorial #23 - Create React App
GraphQL Tutorial #23 - Create React App
Net Ninja
27 GraphQL Tutorial #24 - Book List Component
GraphQL Tutorial #24 - Book List Component
Net Ninja
28 GraphQL Tutorial #25 - Apollo Client Setup
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
29 GraphQL Tutorial #26 - Making Queries from React
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
30 GraphQL Tutorial #27 - Rendering Data in a Component
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
31 GraphQL Tutorial #28 - Add Book Component
GraphQL Tutorial #28 - Add Book Component
Net Ninja
32 GraphQL Tutorial #29 - External Query File
GraphQL Tutorial #29 - External Query File
Net Ninja
33 GraphQL Tutorial #30 - Updating Component State
GraphQL Tutorial #30 - Updating Component State
Net Ninja
34 GraphQL Tutorial #31 - Composing Queries
GraphQL Tutorial #31 - Composing Queries
Net Ninja
35 GraphQL Tutorial #32 - query variables
GraphQL Tutorial #32 - query variables
Net Ninja
36 GraphQL Tutorial #33 - Re-fetching Queries
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
37 GraphQL Tutorial #34 - Book Details Component
GraphQL Tutorial #34 - Book Details Component
Net Ninja
38 GraphQL Tutorial #36 - Styling the App
GraphQL Tutorial #36 - Styling the App
Net Ninja
39 GraphQL Tutorial #35 - Making a Single Query
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
40 Build Apps with Vue & Firebase - Udemy Course
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
41 Updated Vue & Firebase Course (Udemy)
Updated Vue & Firebase Course (Udemy)
Net Ninja
42 Vue & Firebase Real-time Chat (Preview) #1 - Intro
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
43 Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
44 Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
45 Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
46 Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
47 Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
48 Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
49 Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
50 Object Oriented JavaScript Tutorial #1 - Introduction
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
51 Object Oriented JavaScript Tutorial #2 - Object Literals
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
52 Object Oriented JavaScript Tutorial #3 - Updating Properties
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
53 Object Oriented JavaScript Tutorial #4 - Classes
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
54 Object Oriented JavaScript Tutorial #5  - Class Constructors
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
55 Object Oriented JavaScript Tutorial #6 - Class Methods
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
56 Object Oriented JavaScript Tutorial #7 - Method Chaining
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
57 Object Oriented JavaScript Tutorial #8 - Class Inheritance
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
58 Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
59 Object Oriented JavaScript Tutorial #10 - Prototype
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
60 Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja

This tutorial teaches how to add custom tab bar icons to a React Native app using Expo Vector Icons. It covers installing the package, importing the IonIcons component, and dynamically setting the icon and color based on the tab's focus state.

Key Takeaways
  1. Install Expo Vector Icons package using npm or yarn
  2. Import IonIcons component from expo/vector-icons
  3. Add tab bar icon property to each tab
  4. Destructure focused property and use it to dynamically set icon and color
  5. Use theme colors to set icon color based on focus state
💡 Using the focused property to dynamically set the icon and color based on the tab's focus state allows for a more interactive and engaging user interface.

Related Reads

📰
ORM tipado con migraciones automáticas: Fitz vs SQLAlchemy + Alembic + Pydantic
Learn how to implement a typed ORM with automatic migrations in Python using Fitz, SQLAlchemy, Alembic, and Pydantic
Dev.to · Martin Palopoli
📰
The one-click gap nobody was solving: why I built HTML Deployer
Learn how HTML Deployer solves the one-click deployment gap for HTML projects and why it matters for developers
Dev.to · Julie Do
📰
Why Every Developer Should Learn Backend (Even If You Love AI or Frontend)
Learning backend development is crucial for all developers, regardless of their primary focus, to create comprehensive and scalable applications
Medium · AI
📰
7 Apache Kafka Design Patterns Every Backend Engineer Should Know
Learn 7 essential Apache Kafka design patterns for building scalable and efficient real-time data streaming systems
Medium · Programming
Up next
Indian Express Editorial Analysis by Chandan Sharma - 1 JULY 2026 | UPSC Current Affairs 2026
StudyIQ IAS
Watch →