Understanding and effectively using common style properties is essential for creating visually appealing and functional mobile apps.
flex
, flexDirection
, justifyContent
, alignItems
width
, height
, padding
, margin
color
, fontSize
, fontWeight
, textAlign
borderWidth
, borderColor
, borderRadius
shadowColor
, shadowOffset
, shadowOpacity
, shadowRadius
Consider you need to style a button in the “JUST-Learning” app to enroll in a course. The button should be prominent and visually appealing.
import React from 'react';
import { StyleSheet, View, Text, TouchableOpacity } from 'react-native';
const EnrollButton = () => {
return (
<TouchableOpacity style={styles.button}>
<Text style={styles.buttonText}>Enroll Now</Text>
</TouchableOpacity>
);
};
const styles = StyleSheet.create({
button: {
backgroundColor: '#007bff',
padding: 16,
borderRadius: 8,
alignItems: 'center',
marginVertical: 8,
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.2,
shadowRadius: 4,
},
buttonText: {
fontSize: 16,
fontWeight: 'bold',
color: '#fff',
},
});
export default EnrollButton;
In this lesson, you explored common style properties in React Native and saw practical examples of their use. These properties form the building blocks of effective styling in your apps.