To make application Look and feel we need to apply some style for it.
We have different ways to apply styles in React-Native
Inline style: We can use the style property to add the styles inline. But this is not best practice because it can be hard to read the code.
In this chapter, we will use the Stylesheet for styling
Lets check example
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import PresentorComponentfrom './PresentorComponent'
export default class App extends React.Component {
state = {
myState: 'This is my state'
}
render() {
return (
<View>
<PresentorComponent myState = {this.state.myState}/>
</View>
);
}
}
|
PresentorComponent
IHere we will import the StyleSheet. At the bottom of the file, we will create our stylesheet and assign it to the styles constant.
Note : Styles are in camelCase and we do not use px or % for styling.
To apply styles to our text, we need to add style = {styles.myText} property to the Text element.
PresentorComponent.js
class PresentorComponent extends React.Component { render() { return <Text>This is from Props {this.props.id}</Text>; } }
const styles = StyleSheet.create ({
myState: {
marginTop: 20,
textAlign: 'center',
color: 'blue',
fontWeight: 'bold',
fontSize: 20
}
})
|
That's this is very simple application to apply style for React Components.
Ruby program to add two integer numbers
how to create an array with Array.[](*args) in Ruby ?
What are the various Ruby runtimes, and how are they different?
Ruby program to check whether the given number is prime or not
Ruby program to reverse a string
Ruby program to check whether the given number is palindrome
Ruby program to print Fibonacci series
How to Replace array elements in Ruby?
Ruby program to print an array
Ruby program to check whether the given number is Armstrong
Program to Print Triangle of Numbers in Ruby
How to add/remove elements to Array in Ruby?
How to shuffle an array in Ruby?
Creating Array with Array.new(size, obj) in Ruby
Ruby program to generate random numbers
Ruby program to Calculate the factorial of given number
What are #method_missing and #send? Why are they useful?
How to Sort Array in Ruby?
How to get index of array element in Ruby
How to Get Input with Gets in Ruby
How to create two dimensional array in ruby?
Reat Native Google Maps integration