Curriculum
Course: Styling in React Native
Login

Curriculum

Styling in React Native

Text lesson

Lesson 1: Overview of Styling in React Native

Introduction

Styling is a critical aspect of mobile app development that enhances the user experience and makes the app visually appealing. React Native provides several methods to style components, each tailored to fit the unique needs of mobile platforms.

 

Key Differences from Web Development

In React Native, styles are written in JavaScript, not CSS. This allows styles to be dynamically generated and altered at runtime, offering greater flexibility. Unlike CSS which applies globally, styles in React Native are scoped to the component.

 

Core Concepts
  • StyleSheet Object: A core utility provided by React Native to define styles in a structured way. Styles are created using StyleSheet.create which provides validation and performance optimizations.
  • Inline Styling: Directly applying styles to components, useful for dynamic styles and simple scenarios.
Real World Scenario: JUST-Learning App

Imagine you are styling the homepage of “JUST-Learning,” an online learning platform focused on web and mobile app development courses. The homepage should greet users with a welcoming message and showcase featured courses.

Example Code:
import React from 'react';
import { StyleSheet, View, Text } from 'react-native';

const HomePage = () => {
return (
<View style={styles.container}>
<Text style={styles.greeting}>Welcome to JUST-Learning</Text>
<Text style={styles.subText}>Explore our featured courses below:</Text>
</View>

);
};

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#f0f0f0',
padding: 16,
},
greeting: {
fontSize: 24,
fontWeight: 'bold',
color: '#333',
marginBottom: 8,
},
subText: {
fontSize: 16,
color: '#666',
},
});

export default HomePage;

 
Conclusion

In this lesson, you learned about the fundamental differences between web and mobile styling, and the core concepts of styling in React Native. Mastering these basics will set the foundation for more advanced techniques.

Layer 1
Login Categories
This website uses cookies and asks your personal data to enhance your browsing experience.