Sign in Go Pro

Build a React Native Application

Displaying Images and Icons in React Native

This lesson is for PRO members.

Upgrade today to get access to all the PRO lessons.

Unlock this lesson
Autoplay

Up next

Previous

About

Importing and using images can be accomplished by including the images in your app's source, and references the image using a regular import.

Icons are also easy to setup and use, by utilizing an icon font. We use the icons that come packaged with Native Base to add open circles and checkmarks to the todo items.

Images

Star and Checkmark images here

Summary of Content:

  • Download 1x, 2x, and 3x version of icons
  • Import icons, and use them with the Image component
  • Add that image to the tab bar
  • Using an icon font set
  • Styling icons and images

Instructor

Links

Comments

Make sure you don't use react-navigation 2 because it doesn't work well (it doesn't show the check icon plus it produces a deprecation warning).

The code of the video is not working!

In line 31 of file App.js there is:

"...TabNavigator.Presets.iOSBottomTabs"

But, this is deprecated since it has been updated this file in Lessons 12 "React Native Routing and Navigation with the React Navigation Library":
https://caster.io/lessons/react-native-routing-and-navigation-with-the-react-navigation-library

It has been changed from line 10:
"import { TabNavigator, StackNavigator } from 'react-navigation'"
to
"import { createAppContainer } from 'react-navigation';
import { createBottomTabNavigator } from 'react-navigation-tabs';
import { createStackNavigator } from 'react-navigation-stack';"

So we need to replace line 31 "...TabNavigator.Presets.iOSBottomTabs" to something, some code.

I was trying to adapt the code below to the example of this current lesson:
https://snack.expo.io/@react-navigation/stacks-in-tabs

I tried that and it didn't work.

``
const TabNav = createBottomTabNavigator({
TodoNav: { screen: TodoNav },
About: { screen: About },
},
{
navigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
let iconName;
if (routeName === 'TodoNav') {
iconName =
check;
} else if (routeName === 'About') {
iconName =
star`;
}

// You can return any component that you like here! We usually use an
// icon component from react-native-vector-icons
return ;
},
}),
tabBarPosition: 'bottom',
tabBarOptions: {
activeTintColor: '#0066CC',
showIcon: false,
labelStyle: {
fontSize: 12
},
},
// ...createBottomTabNavigator.Presets.iOSBottomTabs
})
```

After new attempt I got a new code for App.js, that produces this result:
http://bit.ly/2P4oiZe

Where is the TodoNav icon?

Here is the App.js source code:

```
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';

// import { TabNavigator, StackNavigator } from 'react-navigation'
import { createAppContainer } from 'react-navigation';
import { createBottomTabNavigator } from 'react-navigation-tabs';
import { createStackNavigator } from 'react-navigation-stack';
import Animated from 'react-native-reanimated';

import ToDoList from './src/components/TodoList'
import About from './src/components/About'
import AddTodo from './src/components/AddTodo'

const TodoNav = createStackNavigator({
TodoList: { screen: ToDoList },
AddTodo: { screen: AddTodo }
}, {
mode: 'modal'
})

const TabNav = createBottomTabNavigator({
TodoNav: { screen: TodoNav },
About: { screen: About },
}, {
tabBarPosition: 'bottom',
tabBarOptions: {
activeTintColor: '#0066CC',
showIcon: true,
labelStyle: {
fontSize: 12
},
},
// ...createBottomTabNavigator.Presets.iOSBottomTabs
})

const Apps = createAppContainer(TabNav)

type Props = {};
export default class App extends Component {
render() {
return (

);
}
}

const styles = StyleSheet.create({
});
```

Now, finally, problem solved!

Here is the updated App.js:

```
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';

// import { TabNavigator, StackNavigator } from 'react-navigation'
import { createAppContainer } from 'react-navigation';
import { createBottomTabNavigator } from 'react-navigation-tabs';
import { createStackNavigator } from 'react-navigation-stack';
import Animated from 'react-native-reanimated';

import ToDoList from './src/components/TodoList'
import About from './src/components/About'
import AddTodo from './src/components/AddTodo'

const TodoNav = createStackNavigator({
TodoList: { screen: ToDoList },
AddTodo: { screen: AddTodo }
}, {
mode: 'modal'
})

const TabNav = createBottomTabNavigator({
TodoNav: { screen: ToDoList }, <<<<<<<<<<-------------------------------------------------- LINE CHANGED
About: { screen: About },
}, {
tabBarPosition: 'bottom',
tabBarOptions: {
activeTintColor: '#0066CC',
showIcon: true,
labelStyle: {
fontSize: 12
},
},
// ...createBottomTabNavigator.Presets.iOSBottomTabs
})

const Apps = createAppContainer(TabNav)

type Props = {};
export default class App extends Component {
render() {
return (

);
}
}

const styles = StyleSheet.create({
});
```

So the change was:

FROM
TodoNav: { screen: TodoNav },
TO
TodoNav: { screen: ToDoList },

>

Lessons in Build a React Native Application

1. Installing React Native and Creating Your First React Native App
02:17
Chris Achard
2. Editing the React Native Component to Display Data on the UI
03:20
Chris Achard
3. Extracting and Writing React Native Components
03:23
Chris Achard
4. Debugging Errors in React Native
03:41
Chris Achard
5. Reuse Components with Props in React Native
01:57
Chris Achard
6. Make React Native Components Dynamic with State
03:11
Chris Achard
7. Dynamically Rendering Components in React Native
Pro
01:28
Chris Achard
8. Rendering Lists in React Native with ScrollView and FlatList
Pro
02:06
Chris Achard
9. Styling React Native Components
Pro
04:18
Chris Achard
10. Layout Components in React Native with Flexbox
Pro
03:28
Chris Achard
11. Installing and Using Third Party React Native Libraries
Pro
03:31
Chris Achard
12. React Native Routing and Navigation with the React Navigation Library
Pro
03:48
Chris Achard
13. Reacting to Input Events with React Native Controlled Components
Pro
02:23
Chris Achard
14. Setting State in React Native with setState
Pro
03:03
Chris Achard
15. Exploring Lifecycle Methods in React Native
Pro
02:18
Chris Achard
16. Consuming a Node.js HTTP API in React Native
Pro
05:16
Chris Achard
17. Displaying Images and Icons in React Native
Pro
04:26
Chris Achard
18. Deleting a ToDo Item from a React Native List
Pro
01:31
Chris Achard
19. Refactoring Network Code into a React Native Shared Library
Pro
01:38
Chris Achard
20. Platform Specific React Native Code and Styles
Pro
03:13
Chris Achard
21. Filtering Data with a React Native Segment Component
Pro
02:01
Chris Achard
22. Deploying a React Native Application to a iOS or Android Device
Pro
02:17
Chris Achard
23. Building a React Native Android APK for Google Play
Pro
02:12
Chris Achard
24. Building a React Native iOS IPA file for the App Store
Pro
01:29
Chris Achard