View is the most common element in React Native. We can consider it as an equivalent of the div element used in web development.
When we need to wrap our elements inside the container, we can use View as a container element.
When we want to nest more elements inside the parent element, both parent and child can be View. It can have as many children as you want.
When we want to style different elements, we can place them inside View since it supports style property, flexbox etc.
View also supports synthetic touch events, which can be useful for different purposes.
Lets check Example
import React from 'react'; import {StyleSheet, View, Text} from 'react-native'; import {Component} from 'react';
export default class Views extends Component { render() { return ( <View style={mystyle.container}> <View style={mystyle.header}> <Text style={mystyle.boldText}>Header</Text> </View> <View style={mystyle.body}> <Text style={mystyle.text}>Hello, World!</Text> </View> </View> ); } } const mystyle = StyleSheet.create({ container: { flex: 1, backgroundColor: '#FAFAFA', alignItems: 'center', alignContent: 'center', },
header: { backgroundColor: 'green', width: '100%', alignContent: 'center', alignItems: 'center', padding: 20, }, boldText: { fontWeight: 'bold', color: 'white', fontSize: 20, }, text: { fontWeight: 'normal', color: 'red', fontSize: 20, }, body: { width: '100%', flex: 1, backgroundColor: 'yellow', padding: 20, }, });
|
Output
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?