Images and backgrounds play a significant role in the visual appeal of a mobile app. React Native provides various ways to style and manipulate these elements.
Consider the course detail screen of the “JUST-Learning” app. It should feature a prominent background image and course thumbnail to attract users.
import React from 'react';
import { StyleSheet, View, Text, Image, ImageBackground } from 'react-native';
const CourseDetail = () => {
return (
<ImageBackground source={{ uri: 'https://example.com/background.jpg' }} style={styles.background}>
<View style={styles.container}>
<Image source={{ uri: 'https://example.com/course-thumbnail.jpg' }} style={styles.thumbnail} />
<Text style={styles.title}>Advanced React Native</Text>
<Text style={styles.description}>Deep dive into advanced topics of React Native.</Text>
</View>
</ImageBackground>
);
};
const styles = StyleSheet.create({
background: {
flex: 1,
resizeMode: 'cover',
justifyContent: 'center',
alignItems: 'center',
},
container: {
padding: 16,
backgroundColor: 'rgba(255, 255, 255, 0.8)',
borderRadius: 8,
alignItems: 'center',
},
thumbnail: {
width: 150,
height: 150,
borderRadius: 8,
marginBottom: 16,
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 8,
},
description: {
fontSize: 16,
color: '#666',
},
});
export default CourseDetail;
In this lesson, you learned how to work with images and backgrounds in React Native. These techniques are vital for creating visually engaging and attractive mobile apps.