React Native doesn't include icons by default. In the Expo ecosystem, we use @expo/vector-icons, which bundles several popular icon sets like Ionicons, FontAwesome, and Material Design.
npm expo install @expo/vector-icons
import { Ionicons } from '@expo/vector-icons';
tabBarIcon PropertyTo replace the default triangles, we use the tabBarIcon property inside the options prop of a Tabs.Screen.
tabBarIcon is a function that receives an object. We destructure { focused } from this object to know if the tab is currently active.<Ionicons />).A common UI pattern in mobile apps is to show an outlined icon when a tab is inactive and a filled icon when it is focused. We use a ternary operator to switch names:
tabBarIcon: ({ focused }) => (
<Ionicons
size={24}
name={focused ? 'person': 'person-outline'}
color={focused ? theme.iconColorFocused : theme.iconColor}
/>
)
Here is how the individual screens are configured in the (dashboard)/_layout.jsx:
| Screen | Focused Icon | Unfocused Icon |
|---|---|---|
| Books | book |
book-outline |
| Create | create |
create-outline |
| Profile | person |
person-outline |
Code Snippet:
<Tabs.Screen
name="profile"
options={{
title: "Profile",
tabBarIcon: ({ focused }) => (
<Ionicons
name={focused ? 'person' : 'person-outline'}
size={24}
color={focused ? theme.iconColorFocused : theme.iconColor}
/>
)
}}
/>