-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Description
The problem
We generate a lot of boilerplate code (the ios/
and android/
folders containing the native app code) into people's projects / repositories. This is not uncommon, a lot of frameworks do this, but they generally do it for other reasons. They do it to impose a certain structure that they then expect when running the app. We only expect an index.js file, the rest of the stuff that we generate is just boilerplate that most people never change and/or have a hard time maintaining.
The solution
Generate the Android / iOS apps in a hidden, vcs-ignored folder (e.g. .reactnative/
). This will remove the boilerplate from people's projects and give us greater control over the app templates. It also gives us the freedom to re-generate the templates whenever we please (e.g. when you switch to a newer version of React Native), since they will never be touched by developers. This also means no more upgrade
command, making switching to a new React Native version much easier.
Essentially, the new structure would look something like this:
.
├── .node_modules
│ └── react-native
│ └── ...
├── .react-native
│ ├── android
│ │ └── [generated]
│ └── ios
│ └── [generated]
├── index.js
└── package.json
Challenges
- Project meta-data (e.g. name/label, package name etc.): we would need to store these in
package.json
(can we, or do we have to invent another file?) and read them at generation time. - Managing dependencies: this actually makes it easier. We can scan for rnpm dependencies and add them at generation time. This means we would regenerate every time you add a dependency or even when you execute e.g.
run-android
. - Allowing people to write native code: since the developer doesn't have access to the native projects anymore, this is significantly harder. We can let people supply a “main” rnpm module that lives in the same project and is simply linked at generation time. However, this limits developers to writing native modules and view managers (on Android it would be possible to write secondary Activities and other components like Services, too; not sure about iOS). If they need to change the main entry point (MainActivity / AppDelegate (?)) it would be kinda impossible. However, if you need to do that, your project starts to fall into the “embedding React Native into existing apps” category.
- Embedding React Native into existing apps: we have to continue supporting this. It shouldn't be hard: simply don't use any of the generation stuff and link to the libraries bundled in the node module, write your own MainActivity / AppDelegate using the samples provided.
- We'd have to solve all of these problems on both platforms and in one go, and provide a clear migration path come release time.
Going forward
First, I'm curious what people's thoughts are. Would this be valuable? Are there any huge blockers that I'm not seeing? For example, I'm worried about all rnpm modules having to match a project's react-native dependency version making upgrading hard. But I'm guessing this is already an issue.
Second, I will not have time to work on this anytime soon. I might in the future, but no guarantees. I'd be thrilled to have someone in the community own this though and more than happy to review PRs.