Curriculum
Course: Styling in React Native
Login

Curriculum

Styling in React Native

Text lesson

Lesson 2: Styling Text and TextInput Components

Introduction

Text and TextInput components are fundamental for displaying information and capturing user input in any mobile app. Proper styling of these components enhances readability and usability.

Key Concepts
  • Typography: Font size, weight, color, and style.
  • Text Alignment: Aligning text within its container.
  • TextInput Customization: Styling input fields for a better user experience.
Real World Scenario: JUST-Learning App

Consider the login screen of the “JUST-Learning” app. It needs well-styled text elements and input fields for email and password.

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

const LoginScreen = () => {
return (
<View style={styles.container}>
<Text style={styles.title}>JUST-Learning</Text>
<Text style={styles.subtitle}>Login to your account</Text>
<TextInput style={styles.input} placeholder="Email" keyboardType="email-address" />
<TextInput style={styles.input} placeholder="Password" secureTextEntry />
<TouchableOpacity style={styles.button}>
<Text style={styles.buttonText}>Login</Text>
</TouchableOpacity>
</View>

);
};

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
padding: 16,
backgroundColor: '#f0f0f0',
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 8,
},
subtitle: {
fontSize: 16,
color: '#666',
marginBottom: 16,
},
input: {
width: '100%',
padding: 12,
marginBottom: 12,
borderRadius: 8,
backgroundColor: '#fff',
shadowColor: '#000',
shadowOpacity: 0.1,
shadowRadius: 4,
shadowOffset: { width: 0, height: 2 },
},
button: {
backgroundColor: '#007bff',
padding: 16,
borderRadius: 8,
alignItems: 'center',
marginTop: 16,
width: '100%',
},
buttonText: {
fontSize: 16,
fontWeight: 'bold',
color: '#fff',
},
});

export default LoginScreen;

Best Practices
  • Use consistent typography to maintain a cohesive look.
  • Ensure input fields are accessible and easy to interact with.
Benefits and Limitations
  • Benefits: Proper styling improves readability and user interaction.
  • Limitations: Over-styling can lead to cluttered and confusing interfaces.
 
Conclusion

In this lesson, you learned how to style Text and TextInput components effectively. These skills are crucial for creating clean and user-friendly forms and displays in your app.

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