Lesson 14 of 60 – Image Component in React Native
23%

Image Component in React Native

The Image component is used to display images in React Native applications. Images can come from local files inside your project or from remote URLs on the internet.

Note: Unlike HTML, React Native uses the Image component instead of the HTML <img> element.

1. What is Image?

Image is a built-in React Native component used to display images on a mobile screen.

import { Image } from "react-native";

It can display both local and remote images.

2. Importing Image

The Image component is imported from the react-native package.

import { Image } from "react-native";

It can also be imported together with other components.

import {
    View,
    Text,
    Image
} from "react-native";

3. Basic Image Syntax

<Image
    source={require("./assets/logo.png")}
/>

The source prop specifies which image should be displayed.

4. Local Images

Local images are stored inside the project and can be loaded using require().

For example, suppose the project contains:

assets/
    logo.png

The image can be displayed using:

<Image
    source={require("./assets/logo.png")}
/>

5. Image Width and Height

An Image normally needs explicit dimensions to display correctly.

<Image
    source={require("./assets/logo.png")}
    style={{
        width: 100,
        height: 100
    }}
/>

Here the image is 100 pixels wide and 100 pixels high.

6. Styling an Image

The style prop can be used to control the appearance and size of an Image.

const styles = StyleSheet.create({

    image: {
        width: 150,
        height: 150
    }

});
<Image
    source={require("./assets/logo.png")}
    style={styles.image}
/>

7. Remote Images

Images can also be loaded from a remote URL.

<Image
    source={{
        uri: "https://example.com/image.jpg"
    }}
    style={{
        width: 200,
        height: 200
    }}
/>

For remote images, the uri property is used.

8. Local Image vs Remote Image

Image Type Source Syntax
Local require("./assets/logo.png")
Remote { uri: "https://example.com/image.jpg" }

The syntax of the source prop depends on where the image is stored.

9. Image resizeMode

The resizeMode property controls how an image fits inside its available dimensions.

<Image
    source={require("./assets/logo.png")}
    style={styles.image}
    resizeMode="contain"
/>

Different resize modes are useful for different image layouts.

10. resizeMode contain

contain scales the image so that the complete image fits inside the available space while maintaining its aspect ratio.

<Image
    source={require("./assets/logo.png")}
    style={{
        width: 200,
        height: 150
    }}
    resizeMode="contain"
/>

This is useful when the entire image needs to remain visible.

11. resizeMode cover

cover scales the image to cover the available area while maintaining its aspect ratio.

<Image
    source={require("./assets/banner.jpg")}
    style={{
        width: 300,
        height: 150
    }}
    resizeMode="cover"
/>

Some parts of the image may be cropped.

12. resizeMode stretch

stretch stretches the image to fill the specified dimensions.

<Image
    source={require("./assets/banner.jpg")}
    style={{
        width: 300,
        height: 150
    }}
    resizeMode="stretch"
/>

The image may not maintain its original aspect ratio.

13. resizeMode repeat

The repeat mode repeats the image to fill the available area when supported by the platform.

<Image
    source={require("./assets/pattern.png")}
    style={{
        width: 300,
        height: 200
    }}
    resizeMode="repeat"
/>

14. resizeMode center

The center mode displays the image at its original size when possible and places it in the center of the available area.

<Image
    source={require("./assets/logo.png")}
    style={{
        width: 300,
        height: 200
    }}
    resizeMode="center"
/>

15. Border Radius

The borderRadius style can be used to create rounded images.

const styles = StyleSheet.create({

    image: {
        width: 150,
        height: 150,
        borderRadius: 75
    }

});

A large border radius can be used to create a circular image.

16. Circular Profile Image

Circular images are commonly used for profile pictures.

<Image
    source={require("./assets/profile.jpg")}
    style={{
        width: 100,
        height: 100,
        borderRadius: 50
    }}
/>

The border radius should generally be half of the width and height for a circular image when those dimensions are equal.

17. Image inside View

Image components are commonly placed inside View containers.

<View>

    <Image
        source={require("./assets/logo.png")}
        style={{
            width: 100,
            height: 100
        }}
    />

    <Text>
        Soopro Pathshala
    </Text>

</View>

18. Centering an Image

Flexbox can be used to center an image inside a View.

const styles = StyleSheet.create({

    container: {
        flex: 1,
        justifyContent: "center",
        alignItems: "center"
    },

    image: {
        width: 150,
        height: 150
    }

});
<View style={styles.container}>

    <Image
        source={require("./assets/logo.png")}
        style={styles.image}
    />

</View>

19. Image with Text

Image and Text can be combined to create user interface sections.

<View>

    <Image
        source={require("./assets/profile.jpg")}
        style={{
            width: 100,
            height: 100
        }}
    />

    <Text>
        Rahul Kumar
    </Text>

</View>

20. Image with Dynamic URL

A remote image URL can come from a JavaScript variable.

const imageUrl =
    "https://example.com/profile.jpg";

return (
    <Image
        source={{
            uri: imageUrl
        }}
        style={{
            width: 120,
            height: 120
        }}
    />
);

This is useful when image URLs come from an API.

21. Image from API Data

Many APIs return image URLs as part of their JSON data.

const student = {
    name: "Rahul",
    image: "https://example.com/rahul.jpg"
};

return (
    <View>

        <Image
            source={{
                uri: student.image
            }}
            style={{
                width: 100,
                height: 100
            }}
        />

        <Text>
            {student.name}
        </Text>

    </View>
);

22. Image Background Concept

When an image needs to behave like a background with content placed over it, React Native applications can use components and libraries designed for that purpose.

A common approach is to use ImageBackground.

import {
    ImageBackground,
    Text
} from "react-native";

<ImageBackground
    source={require("./assets/banner.jpg")}
    style={{
        width: 300,
        height: 200
    }}
>

    <Text>
        Welcome
    </Text>

</ImageBackground>

23. Image Loading

Remote images may take time to load because they are downloaded from a network source.

For a better user experience, applications can show loading indicators or placeholder content while remote data and images are being loaded.

<Text>
    Loading image...
</Text>

In real applications, loading state is usually controlled with React state.

24. Image Error Handling

Remote image requests can fail because of an invalid URL or network problems.

React Native provides image events such as onError that can be used to respond to image loading errors.

<Image
    source={{
        uri: "https://example.com/profile.jpg"
    }}
    style={{
        width: 100,
        height: 100
    }}
    onError={() => {
        console.log("Image failed to load");
    }}
/>

25. Image Accessibility

Images that communicate important information should be made understandable to users who rely on accessibility features.

React Native supports accessibility-related properties that can be used to describe interface elements.

<Image
    source={require("./assets/logo.png")}
    style={{
        width: 100,
        height: 100
    }}
    accessible={true}
    accessibilityLabel="Company logo"
/>

26. Image in a Card

<View style={styles.card}>

    <Image
        source={require("./assets/course.jpg")}
        style={styles.courseImage}
        resizeMode="cover"
    />

    <Text style={styles.title}>
        React Native Course
    </Text>

    <Text>
        Learn mobile app development.
    </Text>

</View>

This structure can be used for course cards, product cards and profile cards.

27. Complete Image Example

import {
    View,
    Text,
    Image,
    StyleSheet
} from "react-native";

export default function App() {

    return (
        <View style={styles.container}>

            <Image
                source={require("./assets/profile.jpg")}
                style={styles.profile}
            />

            <Text style={styles.name}>
                Rahul Kumar
            </Text>

            <Text style={styles.course}>
                React Native Student
            </Text>

        </View>
    );
}

const styles = StyleSheet.create({

    container: {
        flex: 1,
        justifyContent: "center",
        alignItems: "center"
    },

    profile: {
        width: 150,
        height: 150,
        borderRadius: 75
    },

    name: {
        marginTop: 20,
        fontSize: 24,
        fontWeight: "bold"
    },

    course: {
        marginTop: 8,
        fontSize: 16
    }

});

28. Image vs HTML img

React Native Web
Image img
source src
require() for local assets Relative URL/path
React Native style system CSS
Mobile application UI Web page UI

29. Best Practices for Images

  • Give images appropriate width and height.
  • Use local assets for images bundled with the application.
  • Use remote URLs when images are provided by an API or server.
  • Choose an appropriate resizeMode.
  • Use borderRadius for rounded or circular images.
  • Handle remote image loading and errors when necessary.
  • Use appropriate image dimensions and formats.
  • Provide accessibility information for meaningful images.
  • Avoid unnecessarily large image files.

30. Complete Image Workflow

Image
 ↓
Choose Source
 ↓
Local / Remote
 ↓
Set Width & Height
 ↓
Apply Style
 ↓
Choose resizeMode
 ↓
Add Border Radius
 ↓
Handle Loading / Errors
 ↓
Display in UI

The Image component is essential for creating profile screens, course cards, product screens, banners, galleries and many other mobile interfaces.

📌 Key Points

  • Image is used to display images in React Native.
  • It is imported from react-native.
  • Local images can be loaded using require().
  • Remote images use a uri inside the source prop.
  • Images should normally have defined dimensions.
  • resizeMode controls how an image fits its area.
  • borderRadius can create rounded and circular images.
  • Images can be combined with View and Text.
  • Remote image loading and errors should be considered in real applications.
  • Accessibility information can improve the experience for users who rely on accessibility features.

🧠 Quick Quiz

Question: Which React Native component is used to display an image?