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
Move HelloWorld template to a single index.js entry point
Summary:
This change (initially discussed in expo/create-react-native-app#26) moves the HelloWorld project template from two nearly identical entry points (`index.android.js` and `index.ios.js`) to a single, minimal `index.js` entry point. The root component is created in `App.js`. This unifies the project structure between `react-native init` and Create React Native App and allows CRNA's eject to use the entry point from the HelloWorld template without any hacks to customize it. Also examples in the docs can be just copy-pasted to `App.js` the same way in both HelloWorld and CRNA apps without having to first learn about `AppRegistry.registerComponent`.
* Created a new project from the template using `./scripts/test-manual-e2e.sh` and verified that:
* The app builds, starts and runs both on Android and iOS.
* Editing and reloading changes works.
* The new files (`index.js`, `App.js`, `__tests__/App.js`) get created in the project folder.
<img width="559" alt="screen shot 2017-08-01 at 19 10 51" src="https://user-images.githubusercontent.com/497214/28835171-300a12b6-76ed-11e7-81b2-623639c3b8f6.png">
<img width="467" alt="screen shot 2017-08-01 at 19 09 12" src="https://user-images.githubusercontent.com/497214/28835180-33d285e0-76ed-11e7-8d68-2b3bc44bf585.png">
<!--
Thank you for sending the PR!
If you changed any code, please provide us with clear instructions on how you verified your changes work. In other words, a test plan is *required*. Bonus points for screenshots and videos!
Please read the Contribution Guidelines at https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md to learn more about contributing to React Native.
Happy contributing!
-->
Closes#15312
Differential Revision: D5556276
Pulled By: hramos
fbshipit-source-id: 068fdf7e51381c2bc50321522f2be0db47296c5e
Copy file name to clipboardExpand all lines: docs/IntegrationWithExistingApps.md
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -292,15 +292,15 @@ Now we will actually modify the native iOS application to integrate React Native
292
292
293
293
The first bit of code we will write is the actual React Native code for the new "High Score" screen that will be integrated into our application.
294
294
295
-
##### 1. Create a `index.ios.js` file
295
+
##### 1. Create a `index.js` file
296
296
297
-
First, create an empty `index.ios.js` file in the root of your React Native project.
297
+
First, create an empty `index.js` file in the root of your React Native project.
298
298
299
-
`index.ios.js` is the starting point for React Native applications on iOS, and it is always required. It can be a small file that `require`s other file that are part of your React Native component or application, or it can contain all the code that is needed for it. In our case, we will just put everything in `index.ios.js`.
299
+
`index.js` is the starting point for React Native applications, and it is always required. It can be a small file that `require`s other file that are part of your React Native component or application, or it can contain all the code that is needed for it. In our case, we will just put everything in `index.js`.
300
300
301
301
##### 2. Add your React Native code
302
302
303
-
In your `index.ios.js`, create your component. In our sample here, we will add simple `<Text>` component within a styled `<View>`
303
+
In your `index.js`, create your component. In our sample here, we will add simple `<Text>` component within a styled `<View>`
Now that your React Native component is created via `index.ios.js`, you need to add that component to a new or existing `ViewController`. The easiest path to take is to optionally create an event path to your component and then add that component to an existing `ViewController`.
361
+
Now that your React Native component is created via `index.js`, you need to add that component to a new or existing `ViewController`. The easiest path to take is to optionally create an event path to your component and then add that component to an existing `ViewController`.
362
362
363
363
We will tie our React Native component with a new native view in the `ViewController` that will actually host it called `RCTRootView` .
364
364
@@ -372,9 +372,9 @@ You can add a new link on the main game menu to go to the "High Score" React Nat
372
372
373
373
We will now add an event handler from the menu link. A method will be added to the main `ViewController` of your application. This is where `RCTRootView` comes into play.
374
374
375
-
When you build a React Native application, you use the React Native packager to create an `index.ios.bundle` that will be served by the React Native server. Inside `index.ios.bundle` will be our `RNHighScore` module. So, we need to point our `RCTRootView` to the location of the `index.ios.bundle` resource (via `NSURL`) and tie it to the module.
375
+
When you build a React Native application, you use the React Native packager to create an `index.bundle` that will be served by the React Native server. Inside `index.bundle` will be our `RNHighScore` module. So, we need to point our `RCTRootView` to the location of the `index.bundle` resource (via `NSURL`) and tie it to the module.
376
376
377
-
We will, for debugging purposes, log that the event handler was invoked. Then, we will create a string with the location of our React Native code that exists inside the `index.ios.bundle`. Finally, we will create the main `RCTRootView`. Notice how we provide `RNHighScores` as the `moduleName` that we created [above](#the-react-native-component) when writing the code for our React Native component.
377
+
We will, for debugging purposes, log that the event handler was invoked. Then, we will create a string with the location of our React Native code that exists inside the `index.bundle`. Finally, we will create the main `RCTRootView`. Notice how we provide `RNHighScores` as the `moduleName` that we created [above](#the-react-native-component) when writing the code for our React Native component.
378
378
379
379
<blockclass="objc" />
380
380
@@ -389,7 +389,7 @@ First `import` the `RCTRootView` header.
let jsCodeLocation =URL(string: "http://localhost:8081/index.ios.bundle?platform=ios")
432
+
let jsCodeLocation =URL(string: "http://localhost:8081/index.bundle?platform=ios")
433
433
let mockData:NSDictionary = ["scores":
434
434
[
435
435
["name":"Alex", "value":"42"],
@@ -471,7 +471,7 @@ Wire up the new link in the main menu to the newly added event handler method.
471
471
472
472
### Test your integration
473
473
474
-
You have now done all the basic steps to integrate React Native with your current application. Now we will start the React Native packager to build the `index.ios.bundle` package and the server running on `localhost` to serve it.
474
+
You have now done all the basic steps to integrate React Native with your current application. Now we will start the React Native packager to build the `index.bundle` package and the server running on `localhost` to serve it.
475
475
476
476
##### 1. Add App Transport Security exception
477
477
@@ -586,15 +586,15 @@ Now we will actually modify the native Android application to integrate React Na
586
586
587
587
The first bit of code we will write is the actual React Native code for the new "High Score" screen that will be integrated into our application.
588
588
589
-
##### 1. Create a `index.android.js` file
589
+
##### 1. Create a `index.js` file
590
590
591
-
First, create an empty `index.android.js` file in the root of your React Native project.
591
+
First, create an empty `index.js` file in the root of your React Native project.
592
592
593
-
`index.android.js` is the starting point for React Native applications on Android, and it is always required. It can be a small file that `require`s other file that are part of your React Native component or application, or it can contain all the code that is needed for it. In our case, we will just put everything in `index.android.js`.
593
+
`index.js` is the starting point for React Native applications, and it is always required. It can be a small file that `require`s other file that are part of your React Native component or application, or it can contain all the code that is needed for it. In our case, we will just put everything in `index.js`.
594
594
595
595
##### 2. Add your React Native code
596
596
597
-
In your `index.android.js`, create your component. In our sample here, we will add simple `<Text>` component within a styled `<View>`:
597
+
In your `index.js`, create your component. In our sample here, we will add simple `<Text>` component within a styled `<View>`:
598
598
599
599
```javascript
600
600
'use strict';
@@ -679,7 +679,7 @@ public class MyReactActivity extends Activity implements DefaultHardwareBackBtnH
@@ -696,7 +696,7 @@ public class MyReactActivity extends Activity implements DefaultHardwareBackBtnH
696
696
}
697
697
```
698
698
699
-
> If you are using a starter kit for React Native, replace the "HelloWorld" string with the one in your index.android.js file (it’s the first argument to the `AppRegistry.registerComponent()` method).
699
+
> If you are using a starter kit for React Native, replace the "HelloWorld" string with the one in your index.js file (it’s the first argument to the `AppRegistry.registerComponent()` method).
700
700
701
701
If you are using Android Studio, use `Alt + Enter` to add all missing imports in your MyReactActivity class. Be careful to use your package’s `BuildConfig` and not the one from the `...facebook...` package.
702
702
@@ -775,7 +775,7 @@ Now your activity is ready to run some JavaScript code.
775
775
776
776
### Test your integration
777
777
778
-
You have now done all the basic steps to integrate React Native with your current application. Now we will start the React Native packager to build the `index.android.bundle` package and the server running on localhost to serve it.
778
+
You have now done all the basic steps to integrate React Native with your current application. Now we will start the React Native packager to build the `index.bundle` package and the server running on localhost to serve it.
779
779
780
780
##### 1. Run the packager
781
781
@@ -798,7 +798,7 @@ Once you reach your React-powered activity inside the app, it should load the Ja
798
798
You can use Android Studio to create your release builds too! It’s as easy as creating release builds of your previously-existing native Android app. There’s just one additional step, which you’ll have to do before every release build. You need to execute the following to create a React Native bundle, which will be included with your native Android app:
If you are feeling curious, you can play around with sample code directly in the web simulators. You can also paste it into your `App.js`, `index.ios.js`, or `index.android.js` file to create a real app on your local machine.
33
+
If you are feeling curious, you can play around with sample code directly in the web simulators. You can also paste it into your `App.js` file to create a real app on your local machine.
37
34
38
35
## What's going on here?
39
36
@@ -48,14 +45,6 @@ is a built-in component that just displays some text.
48
45
49
46
So this code is defining `HelloWorldApp`, a new `Component`. When you're building a React Native app, you'll be making new components a lot. Anything you see on the screen is some sort of component. A component can be pretty simple - the only thing that's required is a `render` function which returns some JSX to render.
50
47
51
-
<divclass="banner-crna-ejected">
52
-
<h3>Projects With Native Code Only</h3>
53
-
<p>
54
-
In the particular example above, <code>HelloWorldApp</code> is registered with the <code>AppRegistry</code>. The <code>AppRegistry</code> just tells React Native which component is the root one for the whole application. It's included in these examples so you can paste the whole thing into your <code>index.ios.js</code> or <code>index.android.js</code> file and get it running. If you have a project from Create React Native App, this is handled for you and it's not necessary to call <code>AppRegistry</code> in your code.
55
-
</p>
56
-
</div>
57
-
58
-
59
48
## This app doesn't do very much
60
49
61
50
Good point. To make components do more interesting things, you need to [learn about Props](docs/props.html).
0 commit comments