React Native Styling
With React Native, you don't use a special language or syntax for defining styles. You just style your application using JavaScript. All of the core components accept a prop named style. The style names and values usually match how CSS works on the web, except names are written using camel casing, e.g backgroundColor rather than background-color.
The style prop can be a plain old JavaScript object. That's the simplest and what we usually use for example code. You can also pass an array of styles - the last style in the array has precedence, so you can use this to inherit styles.
As a component grows in complexity, it is often cleaner to use StyleSheet.create to define several styles in one place.
Examples:
Examples:
const styles = StyleSheet.create({
text: {
fontSize: 20,
textAlign: 'center'
}
})
function MyStyledText ({style, ...rest}) {
return (
<Text
style={[styles.text, style]}
{...rest}
/>
)
}
const styles = StyleSheet.create({
text: {
fontSize: 20,
textAlign: 'center'
}
})
function MyStyledText ({style, ...rest}) {
return (
<Text
style={[styles.text, style]}
{...rest}
/>
)
}
Comments
Post a Comment