react-native/docs/Basics-Component-View.md
Joel Marcey 45b8719ca1 ES6-ify View Basics
Summary: Closes https://github.com/facebook/react-native/pull/8366

Differential Revision: D3477409

Pulled By: caabernathy

fbshipit-source-id: 5906e8dffc7884a6ed527fada5f907702a72c08f
2016-06-23 12:29:04 -07:00

1.2 KiB

id title layout category permalink next
basics-component-view View docs The Basics docs/basics-component-view.html basics-component-textinput

A View is the most basic building block for a React Native application. The View is an abstraction on top of the target platform's native equivalent, such as iOS's UIView.

A View is analogous to using a <div> HTML tag for building websites.

It is recommended that you wrap your components in a View to style and control layout.

The example below creates a View that aligns the string Hello in the top center of the device, something which could not be done with a Text component alone (i.e., a Text component without a View would place the string in a fixed location in the upper corner):

import React, { Component } from 'react';
import { AppRegistry, Text, View } from 'react-native';

class ViewBasics extends Component {
  render() {
    return (
      <View style={{marginTop: 22, alignItems: 'center'}}>
        <Text>Hello!</Text>
      </View>
    );
  }
}

// App registration and rendering
AppRegistry.registerComponent('AwesomeProject', () => ViewBasics);