Complete React Native Tutorial #10 - Tab Bar Icons
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
GraphQL Tutorial #5 - Express App Setup
Net Ninja
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
GraphQL Tutorial #8 - Root Query
Net Ninja
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
GraphQL Tutorial #12 - Author Type
Net Ninja
GraphQL Tutorial #13 - Type Relations
Net Ninja
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
GraphQL Tutorial #18 - Mutations
Net Ninja
GraphQL Tutorial #19 - More on Mutations
Net Ninja
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
GraphQL Tutorial #23 - Create React App
Net Ninja
GraphQL Tutorial #24 - Book List Component
Net Ninja
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
GraphQL Tutorial #28 - Add Book Component
Net Ninja
GraphQL Tutorial #29 - External Query File
Net Ninja
GraphQL Tutorial #30 - Updating Component State
Net Ninja
GraphQL Tutorial #31 - Composing Queries
Net Ninja
GraphQL Tutorial #32 - query variables
Net Ninja
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
GraphQL Tutorial #34 - Book Details Component
Net Ninja
GraphQL Tutorial #36 - Styling the App
Net Ninja
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
Updated Vue & Firebase Course (Udemy)
Net Ninja
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja
More on: React
View skill →Related Reads
📰
📰
📰
📰
ORM tipado con migraciones automáticas: Fitz vs SQLAlchemy + Alembic + Pydantic
Dev.to · Martin Palopoli
The one-click gap nobody was solving: why I built HTML Deployer
Dev.to · Julie Do
Why Every Developer Should Learn Backend (Even If You Love AI or Frontend)
Medium · AI
7 Apache Kafka Design Patterns Every Backend Engineer Should Know
Medium · Programming
🎓
Tutor Explanation
DeepCamp AI