StyleSheet in React Native
1) How to create StyleSheet in React Native
We can create StyleSheet for each component or element in the UI screen rather than creating an inline stylesheet as we saw in previous blog see below example
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
export default function Example() {
return (
<View style={styles.container}>
<Text style={styles.text}>See below StyleSheet for each View</Text>
<View style={styles.firstView} />
<View style={styles.secondView}/>
<View style={styles.thirdView}/>
</View>
)
}
//This is the StyleSheet
const styles = StyleSheet.create({
container: {
flex: 1
},
text: {
textAlign: 'center',
fontWeight:'bold',
fontSize:24,
marginVertical:20
},
firstView:{
backgroundColor:'red',
height:100,
width:100
},
secondView:{
backgroundColor:'yellow',
height:100,
width:200
},
thirdView:{
backgroundColor:'blue',
height:100,
width:300
},
})
OUTPUT
Comments
Post a Comment