Styling dalam React Native (Flexbox & StyleSheet)
Studi Kasus: Membuat Card Component
const CardComponent = () => {
return (
<View style={styles.container}>
<View style={styles.card}>
<View style={styles.imageContainer}>
<Text style={styles.imagePlaceholder}>IMAGE</Text>
</View>
<View style={styles.cardContent}>
<Text style={styles.cardTitle}>Card Title</Text>
<Text style={styles.cardDescription}>
This is a description of the card content. It demonstrates how to
create a nice card layout.
</Text>
<View style={styles.cardFooter}>
<Text style={styles.price}>$29.99</Text>
<View style={styles.button}>
<Text style={styles.buttonText}>Buy Now</Text>
</View>
</View>
</View>
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#f5f5f5",
padding: 20,
justifyContent: "center",
},
card: {
backgroundColor: "white",
borderRadius: 12,
shadowColor: "#000",
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.1,
shadowRadius: 8,
elevation: 5,
},
imageContainer: {
height: 200,
backgroundColor: "#e0e0e0",
borderTopLeftRadius: 12,
borderTopRightRadius: 12,
justifyContent: "center",
alignItems: "center",
},
imagePlaceholder: {
fontSize: 24,
color: "#999",
fontWeight: "bold",
},
cardContent: {
padding: 16,
},
cardTitle: {
fontSize: 22,
fontWeight: "bold",
color: "#2c3e50",
marginBottom: 8,
},
cardDescription: {
fontSize: 14,
color: "#7f8c8d",
lineHeight: 20,
marginBottom: 16,
},
cardFooter: {
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
},
price: {
fontSize: 24,
fontWeight: "bold",
color: "#27ae60",
},
button: {
backgroundColor: "#3498db",
paddingHorizontal: 24,
paddingVertical: 12,
borderRadius: 8,
},
buttonText: {
color: "white",
fontSize: 16,
fontWeight: "600",
},
});