Docs: Basic Components Update

Summary:
This is an improvement to basic components docs.

* I updated the basic components example code to better render components on iOS (added paddingTop).
* I also modified the code to allow reader to easily copy, paste, and then run the code in their project if they followed the 'Getting Started' quick start guide.
* I also added additional copy to clarify suggested usage/guidelines.
Closes https://github.com/facebook/react-native/pull/8292

Differential Revision: D3469943

Pulled By: JoelMarcey

fbshipit-source-id: 21ff6ee13b59741c43d80aab68a38aace0fbfca6
This commit is contained in:
Eric Nakagawa
2016-06-22 10:00:12 -07:00
committed by Facebook Github Bot 6
parent 109e3d79cc
commit 4243d682a0
6 changed files with 85 additions and 33 deletions

View File

@@ -9,24 +9,24 @@ next: basics-component-textinput
A [`View`](/react-native/docs/view.html#content) 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` for building websites.
> A `View` is analogous to using a `<div>` HTML tag for building websites.
While basic components such as `Text` and `Image`, can be displayed without a `View`, this is not generally recommended since the `View` gives you the control for styling and layout of those components.
It is recommended that you wrap your components in a `View` to style and control layout.
This example 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):
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):
```JavaScript
import React from 'react';
import { AppRegistry, Text, View } from 'react-native';
const App = () => {
const AwesomeProject = () => {
return (
<View style={{alignItems: 'center'}}>
<View style={{marginTop: 22, alignItems: 'center'}}>
<Text>Hello!</Text>
</View>
);
}
// App registration and rendering
AppRegistry.registerComponent('MyApp', () => App);
AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);
```