You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Tutorial.md
+17-15Lines changed: 17 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,34 +16,34 @@ We assume you have experience writing websites with React. If not, you can learn
16
16
17
17
## Setup
18
18
19
-
React Native has a few requirements which you can find on the [github page](https://github.com/facebook/react-native#requirements) (specifically OSX, Xcode, Homebrew, node, npm, watchman, and (optionally) flow)
19
+
React Native requires OSX, Xcode, Homebrew, node, npm, and [watchman](https://facebook.github.io/watchman/docs/install.html). [Flow](https://github.com/facebook/flow) is optional.
20
20
21
21
After installing these dependencies there are two simple commands to get a React Native project all set up for development.
22
22
23
23
1.`npm install -g react-native-cli`
24
24
25
-
`react-native-cli` is a command line interface that does the rest of the set up. It’s also an npm module so you can get it very easily. This will install `react-native-cli` so you can run it as a command in your terminal. You only need to do this once ever.
25
+
react-native-cli is a command line interface that does the rest of the set up. It’s installable via npm. This will install `react-native`as a command in your terminal. You only ever need to do this once.
26
26
27
27
2.`react-native init AwesomeProject`
28
28
29
-
This command fetches the React Native source code, installs all of the other npm modules that it depends on, and creates a new Xcode project in `AwesomeProject/AwesomeProject.xcodeproj`.
29
+
This command fetches the React Native source code and dependencies and then creates a new Xcode project in `AwesomeProject/AwesomeProject.xcodeproj`.
30
30
31
31
32
32
## Development
33
33
34
-
You can now open this new project (`AwesomeProject/AwesomeProject.xcodeproj`) in Xcode and simply build and run it with cmd+R. Doing so will start a node server which enables live code reloading by packaging and serving the latest JS bundle to the simulator at runtime. From here out you can see your changes by pressing cmd+R in the simulator rather than recompiling in Xcode.
34
+
You can now open this new project (`AwesomeProject/AwesomeProject.xcodeproj`) in Xcode and simply build and run it with cmd+R. Doing so will also start a node server which enables live code reloading. With this you can see your changes by pressing cmd+R in the simulator rather than recompiling in Xcode.
35
35
36
-
For this tutorial let’s build a simple version of the Movies app that fetches 25 movies that are in theaters and displays them in a ListView.
36
+
For this tutorial we'll be building a simple version of the Movies app that fetches 25 movies that are in theaters and displays them in a ListView.
37
37
38
38
39
39
### Hello World
40
40
41
-
`react-native init` will copy `Examples/SampleProject` to whatever you named your project, in this case AwesomeProject. This is a simple hello world app. You can edit `index.ios.js` to make changes to the app and then press cmd+R in the simulator to see your changes.
41
+
`react-native init` will copy `Examples/SampleProject` to whatever you named your project, in this case AwesomeProject. This is a simple hello world app. You can edit `index.ios.js` to make changes to the app and then press cmd+R in the simulator to see the changes.
42
42
43
43
44
44
### Mocking data
45
45
46
-
Before we write the code to fetch actual Rotten Tomatoes data, let's mock some data so we can get started with rendering some views right away. At Facebook we typically declare constants at the top of JS files just below the requires but feel free to add the following constant wherever you like:
46
+
Before we write the code to fetch actual Rotten Tomatoes data let's mock some data so we can get our hands dirty with React Native. At Facebook we typically declare constants at the top of JS files, just below the requires, but feel free to add the following constant wherever you like:
47
47
48
48
```javascript
49
49
varMOCKED_MOVIES_DATA= [
@@ -54,7 +54,7 @@ var MOCKED_MOVIES_DATA = [
54
54
55
55
### Render a movie
56
56
57
-
We're going to render the title, year, and thumbnail for the movie. Since we want to render an image, which is an Image component in React Native, add Image to the list of React requires above.
57
+
We're going to render the title, year, and thumbnail for the movie. Since thumbnail is an Image component in React Native, add Image to the list of React requires below.
58
58
59
59
```javascript
60
60
var {
@@ -66,7 +66,7 @@ var {
66
66
} = React;
67
67
```
68
68
69
-
Now change the render function so that we're rendering the stuff mentioned above rather than hello world.
69
+
Now change the render function so that we're rendering the data mentioned above rather than hello world.
70
70
71
71
```javascript
72
72
render:function() {
@@ -81,7 +81,7 @@ Now change the render function so that we're rendering the stuff mentioned above
81
81
}
82
82
```
83
83
84
-
Press cmd+R and you should see "Title" sitting above "2015". Notice that the Image doesn't render anything. This is because we haven't specified the width and height of the image we want to render. You do that via styles. While we're changing the styles let's also clean up the styles we're no longer using.
84
+
Press cmd+R and you should see "Title" above "2015". Notice that the Image doesn't render anything. This is because we haven't specified the width and height of the image we want to render. This is done via styles. While we're changing the styles let's also clean up the styles we're no longer using.
85
85
86
86
```javascript
87
87
var styles =StyleSheet.create({
@@ -116,7 +116,7 @@ Press cmd+R and the image should now render.
116
116
117
117
### Add some styling
118
118
119
-
Great, we've rendered our data, now let's make it look better. I'd like to put the text to the right of the image and make the title larger and centered within that area:
119
+
Great, we've rendered our data. Now let's make it look better. I'd like to put the text to the right of the image and make the title larger and centered within that area:
120
120
121
121
```
122
122
+---------------------------------+
@@ -128,7 +128,7 @@ Great, we've rendered our data, now let's make it look better. I'd like to put t
128
128
+---------------------------------+
129
129
```
130
130
131
-
Since we've got some components layed out horizontally and some components layed out vertically, we'll need to add another container around the Texts.
131
+
We'll need to add another container in order to vertically lay out components within horizontally layed out components.
132
132
133
133
```javascript
134
134
return (
@@ -157,6 +157,8 @@ Not too much has changed, we added a container around the Texts and then moved t
157
157
},
158
158
```
159
159
160
+
For layout we use FlexBox which has [great documentation](https://css-tricks.com/snippets/css/a-guide-to-flexbox/).
161
+
160
162
We simply added `flexDirection: 'row'` which means that children are layed out horizontally instead of vertically.
161
163
162
164
```javascript
@@ -165,7 +167,9 @@ We simply added `flexDirection: 'row'` which means that children are layed out h
165
167
},
166
168
```
167
169
168
-
This means that the rightContainer takes up the remaining space in the parent container that isn't taken up by the Image. If this doesn't make sense, add a backgroundColor to rightContainer and then try removing the `flex: 1`. You'll see how the container is only the size of its children instead of taking up the remaining space of its parent.
170
+
This means that the rightContainer takes up the remaining space in the parent container that isn't taken up by the Image. If this doesn't make sense, add a backgroundColor to rightContainer and then try removing the `flex: 1`. You'll see that this causes the container's size to be the minimum size that fits its children.
171
+
172
+
Styling the text is pretty straightforward:
169
173
170
174
```javascript
171
175
title: {
@@ -178,8 +182,6 @@ This means that the rightContainer takes up the remaining space in the parent co
178
182
},
179
183
```
180
184
181
-
This is pretty straightforward if you've ever seen CSS before. Make the title larger, add some space below it, and center all of the text within their parent container (rightContainer).
182
-
183
185
Go ahead and press cmd+R and you'll see the updated view.
0 commit comments