Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move HelloWorld template to a single index.js entry point #15312

Closed
wants to merge 5 commits into from

Conversation

fson
Copy link
Contributor

@fson fson commented Aug 1, 2017

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.

Test plan:

  • 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.

screen shot 2017-08-01 at 19 10 51

screen shot 2017-08-01 at 19 09 12

Use `index.js` as the entry point in the HelloWorld template instead of
the separate `index.android.js` and `index.ios.js` files.
Update references to index.android.js/index.ios.js in the docs.
@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Aug 1, 2017
index.js -> App.js
@pull-bot
Copy link

pull-bot commented Aug 1, 2017

📄 Thanks for your contribution to the docs!

Attention: @facebook/react-native

Generated by 🚫 dangerJS

@hramos
Copy link
Contributor

hramos commented Aug 1, 2017

This is great! I'm slightly concerned that this may make writing different code for iOS and Android less discoverable, but that's something we can address by updating the Platform Specific Code docs.

Does this affect projects that use react-native init? IIRC, the HelloWorld template is a different template than what init uses.

@fson
Copy link
Contributor Author

fson commented Aug 1, 2017

This HelloWorld template is used by react-native init by default (you can specify another template with the --template argument). I've tested the init flow using ./scripts/test-manual-e2e.sh.

Also react-native upgrade and react-native eject use the template. react-native upgrade should not be affected, since it calls copyProjectTemplateAndReplace with the upgrade flag, which tells it to not touch the entry point files. One thing we should still check is that also the HelloNavigation template works correctly after this change. It seems that react-native init uses the HelloWorld template as the base template and then just adds whichever custom template is specified on top.

It's true that getting rid of separate index.ios.js and index.android.js files makes at least that particular method of writing platform specific code (platform-specific file extensions) less discoverable. On the other hand we now show another way in the App.js file, Platform.select(), which is particularly useful for small differences between platforms.

@fson
Copy link
Contributor Author

fson commented Aug 2, 2017

The navigation template is layered on top of the HelloWorld template when you run react-native init Project --template navigation. Therefore I've also adapted it to use App.js, so that it replaces the App.js added from HelloWorld.

The navigation template itself seems to be a bit outdated right now, it's using an older version of react-navigation which isn't compatible with React 16, so I couldn't run it for now. It should work once upgraded.

@facebook-github-bot facebook-github-bot added GH Review: accepted Import Started This pull request has been imported. This does not imply the PR has been approved. and removed GH Review: review-needed labels Aug 3, 2017
@facebook-github-bot
Copy link
Contributor

@hramos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

grabbou pushed a commit to react-native-community/cli that referenced this pull request Sep 26, 2018
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 facebook/react-native#15312

Differential Revision: D5556276

Pulled By: hramos

fbshipit-source-id: 068fdf7e51381c2bc50321522f2be0db47296c5e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Import Started This pull request has been imported. This does not imply the PR has been approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants