🎨 React Native Display Components: Your Visual Storytellers
Imagine you’re building a beautiful house. You need walls, windows, pictures, and lights to make it feel alive. In React Native, Display Components are exactly that—they’re the building blocks that make your app look amazing!
🏠The Big Picture
Think of your phone screen as a blank canvas. Display components are like magic paintbrushes that let you:
- Write words (Text)
- Show pictures (Image)
- Create cool backgrounds (ImageBackground)
- Control the top bar (StatusBar)
- Show loading spinners (ActivityIndicator)
Let’s meet each one!
📝 Text Component: Your App’s Voice
What Is It?
The Text component is like a megaphone for your app. Whenever you want to say something to users, you use Text.
Simple Example
import { Text } from 'react-native';
<Text>Hello, World!</Text>
That’s it! You just made your app say “Hello, World!”
Why It Matters
- Everything written on screen uses Text
- Buttons have Text inside
- Labels, titles, paragraphs—all Text!
graph TD A[Text Component] --> B[Titles] A --> C[Paragraphs] A --> D[Labels] A --> E[Button Text]
🎨 Text Styling: Making Words Beautiful
What Is It?
Just like you pick clothes for school, you can dress up your text! Colors, sizes, bold—all possible.
The Style Object
<Text style={{
fontSize: 24,
color: 'blue',
fontWeight: 'bold'
}}>
I'm Big and Blue!
</Text>
Common Style Properties
| Property | What It Does | Example |
|---|---|---|
fontSize |
Makes text bigger/smaller | 20 |
color |
Changes text color | 'red' |
fontWeight |
Makes text bold | 'bold' |
fontStyle |
Makes text italic | 'italic' |
textAlign |
Centers or aligns text | 'center' |
lineHeight |
Space between lines | 30 |
Real Example
<Text style={{
fontSize: 18,
color: '#333',
fontWeight: '600',
textAlign: 'center',
lineHeight: 26
}}>
Styled text is happy text!
</Text>
✂️ Text Truncation: When Words Don’t Fit
The Problem
Imagine writing a long story on a tiny sticky note. It won’t fit! Same with screens.
The Solution: numberOfLines
<Text numberOfLines={2}>
This is a very long text that
will be cut off after two lines
and show ... at the end
</Text>
How It Works
- Set
numberOfLinesto limit lines - React Native adds
...automatically - No overflow mess!
Example with ellipsizeMode
<Text
numberOfLines={1}
ellipsizeMode="tail"
>
A super long title here...
</Text>
| Mode | Where dots appear |
|---|---|
tail |
At the end… |
head |
…at the start |
middle |
in the…middle |
clip |
No dots, just cut |
🖼️ Image Component: Picture Perfect
What Is It?
The Image component is like a photo frame for your app. It shows pictures from anywhere!
Three Ways to Use Images
1. Local Images (in your project)
import { Image } from 'react-native';
<Image
source={require('./photo.png')}
style={{ width: 100, height: 100 }}
/>
2. Network Images (from internet)
<Image
source={{ uri: 'https://example.com/cat.jpg' }}
style={{ width: 200, height: 200 }}
/>
3. Base64 Images (data strings)
<Image
source={{ uri: 'data:image/png;base64,...' }}
style={{ width: 50, height: 50 }}
/>
Important Rule ⚠️
Network images MUST have width and height!
Resize Modes
<Image
source={{ uri: 'https://...' }}
style={{ width: 200, height: 200 }}
resizeMode="cover"
/>
| Mode | What Happens |
|---|---|
cover |
Fills space, may crop |
contain |
Fits inside, may letterbox |
stretch |
Stretches to fill |
center |
Centers, no resize |
graph TD A[Image Source] --> B[Local File] A --> C[Network URL] A --> D[Base64 Data] B --> E[No size needed] C --> F[Size required!] D --> F
🌄 ImageBackground Component: The Stage Setter
What Is It?
ImageBackground is like a wallpaper that you can put things ON TOP of!
Why Not Just Image?
- Image: Shows a picture
- ImageBackground: Shows a picture with children on top
Simple Example
import { ImageBackground, Text } from 'react-native';
<ImageBackground
source={require('./sunset.jpg')}
style={{ width: 300, height: 200 }}
>
<Text style={{ color: 'white' }}>
Hello on top of image!
</Text>
</ImageBackground>
Real-World Use Case
<ImageBackground
source={{ uri: 'https://...' }}
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center'
}}
resizeMode="cover"
>
<Text style={{
fontSize: 32,
color: 'white',
fontWeight: 'bold'
}}>
Welcome!
</Text>
</ImageBackground>
Key Difference Visualized
graph TD A[Image] --> B[Shows picture only] C[ImageBackground] --> D[Shows picture] D --> E[+ Children on top!]
📊 StatusBar Component: The Control Room
What Is It?
The StatusBar is that thin strip at the very top of your phone—showing time, battery, wifi. You can control it!
Basic Usage
import { StatusBar } from 'react-native';
<StatusBar
barStyle="dark-content"
/>
Bar Styles
| Style | Icon Color | Use When |
|---|---|---|
dark-content |
Dark icons | Light backgrounds |
light-content |
Light icons | Dark backgrounds |
Visual Example
// Light background = dark icons
<StatusBar barStyle="dark-content" />
// Dark background = light icons
<StatusBar barStyle="light-content" />
⚙️ StatusBar Configuration: Full Control
All the Options
<StatusBar
barStyle="light-content"
backgroundColor="#6200EE"
hidden={false}
animated={true}
translucent={false}
/>
Property Breakdown
| Property | What It Does | Values |
|---|---|---|
barStyle |
Icon color | dark-content, light-content |
backgroundColor |
Background color (Android) | Any color |
hidden |
Hide status bar | true, false |
animated |
Smooth transitions | true, false |
translucent |
See-through (Android) | true, false |
Pro Tip: Use Static Methods
// Hide status bar
StatusBar.setHidden(true);
// Change style dynamically
StatusBar.setBarStyle('light-content');
graph TD A[StatusBar Config] --> B[barStyle] A --> C[backgroundColor] A --> D[hidden] A --> E[animated] A --> F[translucent] B --> G[dark-content] B --> H[light-content]
⏳ ActivityIndicator Component: The Waiting Game
What Is It?
The ActivityIndicator is the spinning wheel that tells users “Hold on, something is loading!”
Basic Usage
import { ActivityIndicator } from 'react-native';
<ActivityIndicator />
Customization
<ActivityIndicator
size="large"
color="#0000ff"
/>
Sizes Available
| Size | Use For |
|---|---|
small |
Inline loading, buttons |
large |
Full screen loading |
Real Example: Loading Screen
const [loading, setLoading] = useState(true);
{loading ? (
<ActivityIndicator
size="large"
color="#6200EE"
/>
) : (
<Text>Content loaded!</Text>
)}
Common Pattern
import { View, ActivityIndicator } from 'react-native';
<View style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center'
}}>
<ActivityIndicator
size="large"
color="#FF6B6B"
/>
<Text style={{ marginTop: 10 }}>
Loading...
</Text>
</View>
graph TD A[ActivityIndicator] --> B[Shows Spinner] B --> C[User Knows: Wait!] C --> D[Content Loads] D --> E[Spinner Hides] E --> F[Content Shows]
🎯 Quick Summary
| Component | Purpose | Key Prop |
|---|---|---|
| Text | Display words | style |
| Image | Show pictures | source |
| ImageBackground | Picture + overlay | children |
| StatusBar | Top bar control | barStyle |
| ActivityIndicator | Loading spinner | size, color |
🌟 You Did It!
You just learned the five essential display components in React Native:
- Text - Your app’s voice
- Text Styling - Making words beautiful
- Text Truncation - Handling overflow
- Image - Showing pictures
- ImageBackground - Pictures with content
- StatusBar - Top bar control
- StatusBar Configuration - Full customization
- ActivityIndicator - Loading feedback
These are the building blocks for every beautiful React Native app. Master them, and you’re on your way to creating amazing mobile experiences!
Remember: Every great app started with these simple components. Now go build something awesome! 🚀