Using images affects app speed and battery. Large images can slow UI and use more memory. Remote images need network, causing delays and possible flicker. Local images load faster but increase app size. To keep smooth 60fps, avoid very large images and load only what is visible.
Image component (local and remote) in React Native - Build, Publish & Deploy
Resize images to needed display size before bundling or loading. Use caching for remote images to avoid repeated downloads. Use resizeMode to control scaling efficiently. Lazy load images as user scrolls. Prefer local images for icons and small graphics. Use lightweight formats like WebP if supported.
Local images increase app bundle size, making install bigger and startup slower. Keep local images small and few. Remote images do not add to bundle size but depend on network speed. Balance local and remote images to optimize startup and offline use.
iOS uses UIKit image views under the hood; Android uses native ImageView. iOS supports caching automatically for remote images; Android caching may need extra libraries. Image formats like HEIC are iOS-specific; Android prefers WebP or PNG. Remote image loading behavior and memory limits differ slightly, so test on both.
- Ensure images do not violate copyright or content rules.
- Use appropriate image sizes to avoid excessive app size (Apple HIG recommends keeping app size small).
- Remote images must load securely over HTTPS.
- Provide accessibility labels for images for screen readers.
- Follow platform guidelines for image usage and performance.
Your app takes 5 seconds to load this screen. What's likely wrong?
- Loading very large remote images without caching.
- Using many high-resolution local images increasing bundle size.
- Not resizing images to match display size causing extra memory use.
- Loading all images at once instead of lazy loading.
Practice
Image component?Solution
Step 1: Understand local image usage
Local images require therequire()function to load the file correctly in React Native.Step 2: Check the syntax for local images
The correct syntax usessource={require('path')}, noturiorsrcattributes.Final Answer:
<Image source={require('./assets/photo.png')} /> -> Option CQuick Check:
Local images use require() = C [OK]
- Using uri for local images
- Using src attribute instead of source
- Passing string directly without require()
Solution
Step 1: Identify remote image syntax
Remote images require an object with aurikey inside thesourceprop.Step 2: Verify correct object structure
The correct syntax issource={{ uri: 'URL' }}, not using require or src attributes.Final Answer:
<Image source={{ uri: 'https://example.com/image.png' }} /> -> Option DQuick Check:
Remote images use source={{ uri: URL }} = D [OK]
- Using require() for remote URLs
- Using src attribute instead of source
- Passing URL as a string directly to source
import React from 'react';
import { Image } from 'react-native';
export default function App() {
return (
<Image source={{ uri: 'https://example.com/pic.jpg' }} style={{ width: 100, height: 100 }} accessibilityLabel="Example image" />
);
}Solution
Step 1: Analyze the image source
The source uses a remote URL withuri, so it loads an internet image.Step 2: Check style and accessibility
The style sets width and height to 100, and accessibilityLabel is valid for screen readers.Final Answer:
A 100x100 image loaded from the internet with accessibility label -> Option AQuick Check:
Remote image with size and label = B [OK]
- Forgetting to set width and height style
- Thinking accessibilityLabel causes error
- Assuming remote images won't load
import React from 'react';
import { Image } from 'react-native';
export default function App() {
return (
<Image source="./assets/photo.png" style={{ width: 50, height: 50 }} />
);
}Solution
Step 1: Check source prop for local image
Local images must userequire()inside the source prop, not a string path.Step 2: Verify style and component usage
The style prop is correctly placed and numbers for width/height are valid in React Native.Final Answer:
The source prop should use require() for local images -> Option BQuick Check:
Local images need require() = A [OK]
- Passing string path directly to source
- Misplacing style prop
- Using strings for width/height instead of numbers
Solution
Step 1: Verify local and remote image sources
Local images must userequire(), remote images usesource={{ uri: URL }}.Step 2: Check layout and accessibility
UsingflexDirection: 'row'places images side by side, and accessibilityLabel is correctly added.Final Answer:
Code snippet with require() for local, uri for remote, row layout, and labels -> Option AQuick Check:
Local require + remote uri + row layout = A [OK]
- Using string path instead of require() for local images
- Using uri with local file paths
- Missing accessibility labels
- Incorrect flexDirection for horizontal layout
Ready to prove it?
Pass the test and this pattern moves unknown
