Recently I faced a peculiar situation through a development process of a React Native app.
I thought it would be interesting to share my experience so it might be helpful for those like me who made tons of searches on the net looking for a light.
The first and simple thought is to copy the project and customize it for that company. Pretty clean, totally independent projects with their own specific settings. But all of a sudden you may question yourself: what if we have hundreds of variants in the future and a bug is reported on the cart component for example. Certainly this is an important fix that has to be done for all variants of the app and turns out we have to make the same changes for ALL OF THEM. That would be a huge time consumer.
Ok, the second thought is to have the same project for all of them. So everything is concentrated on the same code and we have a configuration file to deal with the setting for each version. I came across several solutions related to this one but involving development and production versions. That is not my case but maybe it could work, so I took some time to check it out but turns out that I was blocked by the native codes. There is not a viable way to change the package name of the Android app for example, so do it manually every time I have to make a build or even debug the app is out of context. In the middle of this process I found the package react-native-config that helps you to create variables and use them in .plist files for example, maybe it could be useful for another project.
Yes, that simple. And the keyword for the complete answer is Git.
We take all we need and put on control version, a configuration file was written to deal with the dynamic data. This file is specific for each project so this should not be under control version. I wrote a quick tutorial to get it a little bit clear.
We start by creating a new React Native project:
react-native init my-base-project
Once you have the project created, the first variant is built normally with all the features. After finishing the release of the first version of the app, if you need to create another variant for some other company you can just edit the .gitignore file adding the following lines:
That will be the .gitignore file for all variants. The main idea is to deal only with the files that all projects have in common and can be managed dynamically through our configuration file that is types.js included on .gitignore.
export const PRIMARY_COLOR = 'blue';
export const SECONDARY_COLOR = 'white';
At first it seems to be a bit strange because this files are included by default on control version, but this time they are not allowed in our control version due the fact they contain specific information about the app, so we cannot generalize for all variants. For example the /package.json generated by React Native and contains specific information for each project, so you shouldn’t change it unless you’re 100% sure of what you’re doing.
We left both native projects iOS and Android out of Git as we are not able to customize them dynamically through JS. I followed the same logic for all files in my project so in the end you have to choose which files will be kept under control version to make your life easier.
Once you have finished a feature that you were working on or a bug fix you simply push them to your repository and to work in another variant all you have to do is pull them. Easy-peasy!
I know that still doesn’t solve the problem of having to install another package, or having to edit something on native projects, like push notification configuration that, in my case, was made through native configuration because each variant has it’s own project, but I think that’s still an exception and for now it’s working pretty well for me. I’m still working with the limitations of React Native, but if you're facing a similar situation maybe could be a good solution for you as well.