Skip to content

Commit ace261b

Browse files
JoelMarceybubblesunyum
authored andcommitted
Separate Out Core Components Into Individual Parts
Summary: Will create new issue to add more information to the `Components` section of the Tutorial since that was gutted by this change. Fixes facebook#8156 Closes facebook#8256 Differential Revision: D3459601 Pulled By: JoelMarcey fbshipit-source-id: 4038afc463bffcf8efda36d29bc7c443bbc8f4bd
1 parent 7a5001e commit ace261b

9 files changed

+184
-146
lines changed

docs/Basics-Component-Image.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
id: basics-component-image
3+
title: Image
4+
layout: docs
5+
category: Basics
6+
permalink: docs/basics-component-image.html
7+
next: basics-component-view
8+
---
9+
10+
The other basic React Native component is the [`Image`](/react-native/docs/image.html#content) component. Like `Text`, the `Image` component simply renders an image.
11+
12+
> An `Image` is analogous to using `img` when building websites.
13+
14+
The simplest way to render an image is to provide a source file to that image via the `source` attribute.
15+
16+
This example displays a checkbox `Image` on the device.
17+
18+
```JavaScript
19+
import React from 'react';
20+
import { AppRegistry, Image } from 'react-native';
21+
22+
const App = () => {
23+
return (
24+
<Image source={require('./img/check.png')} />
25+
);
26+
}
27+
28+
// App registration and rendering
29+
AppRegistry.registerComponent('MyApp', () => App);
30+
```

docs/Basics-Component-ListView.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
id: basics-component-listview
3+
title: ListView
4+
layout: docs
5+
category: Basics
6+
permalink: docs/basics-component-listview.html
7+
next: basics-integration-with-existing-apps
8+
---
9+
10+
On mobile devices, lists are a core element in many applications. The [`ListView`](/react-native/docs/listview.html#content) component is a special type of [`View`](/react-native/docs/tutorial-component-view.html) that displays a vertically scrolling list of changing data.
11+
12+
The `ListView` component requires two properties, `dataSource` and `renderRow`. `dataSource` is the actual source of information that will be part of the list. `renderRow` takes the data and returns a renderable component to display.
13+
14+
This example creates a simple `ListView` of hardcoded data. It first initializes the `datasource` that will be used to populate the `ListView`. Then it renders that `ListView` with that data.
15+
16+
> A `rowHasChanged` function is required to use `ListView`. Here we just say a row has changed if the row we are on is not the same as the previous row.
17+
18+
```JavaScript
19+
import React from 'react';
20+
import { AppRegistry, Text, View, ListView} from 'react-native';
21+
22+
var SimpleList = React.createClass({
23+
// Initialize the hardcoded data
24+
getInitialState: function() {
25+
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
26+
return {
27+
dataSource: ds.cloneWithRows(['John', 'Joel', 'James', 'Jimmy', 'Jackson', 'Jillian', 'Julie'])
28+
};
29+
},
30+
render: function() {
31+
return (
32+
<View>
33+
<ListView
34+
dataSource={this.state.dataSource}
35+
renderRow={(rowData) => <Text>{rowData}</Text>}
36+
/>
37+
</View>
38+
);
39+
}
40+
});
41+
42+
// App registration and rendering
43+
AppRegistry.registerComponent('MyApp', () => SimpleList);
44+
```

docs/Basics-Component-Text.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
id: basics-component-text
3+
title: Text
4+
layout: docs
5+
category: Basics
6+
permalink: docs/basics-component-text.html
7+
next: basics-component-image
8+
---
9+
10+
The most basic component in React Native is the [`Text`](/react-native/docs/text.html#content) component. The `Text` component simply renders text.
11+
12+
This example displays the `string` `"Hello World!"` on the device.
13+
14+
```JavaScript
15+
import React from 'react';
16+
import { AppRegistry, Text } from 'react-native';
17+
18+
const App = () => {
19+
return (
20+
<Text>Hello World!</Text>
21+
);
22+
}
23+
24+
// App registration and rendering
25+
AppRegistry.registerComponent('MyApp', () => App);
26+
```

docs/Basics-Component-TextInput.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
id: basics-component-textinput
3+
title: TextInput
4+
layout: docs
5+
category: Basics
6+
permalink: docs/basics-component-textinput.html
7+
next: basics-component-listview
8+
---
9+
10+
Direct text-based user input is a foundation for many apps. Writing a post or comment on a page is a canonical example of this. [`TextInput`](/react-native/docs/textinput.html#content) is a basic component that allows the user to enter text.
11+
12+
This example creates a simple `TextInput` box with the `string` `Hello` as the placeholder when the `TextInput` is empty.
13+
14+
```JavaScript
15+
import React from 'react';
16+
import { AppRegistry, TextInput, View } from 'react-native';
17+
18+
const App = () => {
19+
return (
20+
<View>
21+
<TextInput placeholder="Hello" />
22+
</View>
23+
);
24+
}
25+
26+
// App registration and rendering
27+
AppRegistry.registerComponent('MyApp', () => App);
28+
```

docs/Basics-Component-View.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
id: basics-component-view
3+
title: View
4+
layout: docs
5+
category: Basics
6+
permalink: docs/basics-component-view.html
7+
next: basics-component-textinput
8+
---
9+
10+
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`.
11+
12+
> A `View` is analogous to using a `div` for building websites.
13+
14+
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.
15+
16+
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):
17+
18+
```JavaScript
19+
import React from 'react';
20+
import { AppRegistry, Text, View } from 'react-native';
21+
22+
const App = () => {
23+
return (
24+
<View style={{alignItems: 'center'}}>
25+
<Text>Hello!</Text>
26+
</View>
27+
);
28+
}
29+
30+
// App registration and rendering
31+
AppRegistry.registerComponent('MyApp', () => App);
32+
```

docs/Basics-Components.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
id: basics-components
3+
title: Components
4+
layout: docs
5+
category: Basics
6+
permalink: docs/basics-components.html
7+
next: basics-component-text
8+
---
9+
10+
Components are the building blocks for a React Native application. A React Native user interface (UI) is specified by declaring components, possibly nested, and then those components are mapped to the native UI on the targeted platform.
11+
12+
## Core Components.
13+
14+
React Native has a number of core components that are commonly used in applications, either on their own or combined to build new components.
15+
16+
- [Text](/react-native/docs/tutorial-component-text.html)
17+
- [Image](/react-native/docs/tutorial-component-image.html)
18+
- [View](/react-native/docs/tutorial-component-view.html)
19+
- [TextInput](/react-native/docs/tutorial-component-textinput.html)
20+
- [ListView](/react-native/docs/tutorial-component-listview.html)

docs/Tutorial-IntegrationWithExistingApps.md renamed to docs/Basics-IntegrationWithExistingApps.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
id: tutorial-integration-with-existing-apps
2+
id: basics-integration-with-existing-apps
33
title: Integration With Existing Apps
44
layout: docs
5-
category: Tutorials
6-
permalink: docs/tutorial-integration-with-existing-apps.html
5+
category: Basics
6+
permalink: docs/basics-integration-with-existing-apps.html
77
next: sample-application-movies
88
---
99

docs/QuickStart-GettingStarted.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Getting Started
44
layout: docs
55
category: Quick Start
66
permalink: docs/getting-started.html
7-
next: tutorial-core-components
7+
next: basics-components
88
---
99

1010

docs/Tutorial-CoreComponents.md

Lines changed: 0 additions & 142 deletions
This file was deleted.

0 commit comments

Comments
 (0)