Code Monkey home page Code Monkey logo

red-vs-blue's Introduction

RED vs BLUE

React Native white label by config

Context

This demo React Native application showcases a simple white label implementation by environment configuration. This means:

  • One codebase.
  • Centralised config for Android, iOS and JS variables.
  • No flavors, no extra schemes, no extra targets.
  • No hassle. Just run:
yarn ios:red
yarn ios:blue

To get:

screenshot

yarn android:red
yarn android:blue

To get:

screenshot

Approach

The demo setup was achieved using the following steps.

  1. React native init.
  2. Add and configure react-native-ultimate-config. (Their comprehensive documentation is amazing ๐Ÿคฉ)
  3. Set up .env files for each white label. I chose RED (.env.red) and BLUE (.env.blue).
  4. Set the environment variables for the app name and unique identifier and icon names.
  5. (optional) Set up asset folders for each white label and add a hook script to copy the content into the res and xcimages folders when switching env files.
  6. (optional) Add yarn scripts to switch env file and run the correct build.

For a more detailed explanation you can check the commits of this project. They follow the above steps, starting with a common asset pool and then extracting them into separate folders as suggested in step 5.

When to choose this approach

  • When you need to run out a few white label versions of your RN app.
  • When you want to keep the codebase as consistent as possible between those white label versions.

When NOT to choose this approach

When you want the white label versions to have differences beyond theme variables and feature flags. For example when different white labels will have different dependencies, you may be better off splitting into XCode targets/schemes and Android flavors. This is outside the scope of my research. There is experimental support for flavors and schemes in react-native-ultimate-config, but since these functionalities are intertwined within the build process it will probably never be completely supported.

In my personal opinion you would probably be better off splitting your project into separate apps that use common functionality through shared libraries in those cases.

Gotcha's

  • When setting a dynamic android applicationId you must supply it to react-native run-android or it can not auto-launch the app after building. I chose to add this into the yarn scripts for convenience.

red-vs-blue's People

Contributors

dependabot[bot] avatar isilher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

red-vs-blue's Issues

manage assets and more?

Hey, @isilher ,

first of all thank you for putting effort into this example.

I wanted to discuss something I noticed in your readme:

When NOT to choose this approach
When you have to run a LOT of white label versions, you may want a setup that has a stricter separation between assets.

What kind of assets are you referring here? Icons? Something else beyond?

When you want the white label versions to have differences beyond theme variables and feature flags. For example when different white labels will have different dependencies, you may be better off splitting into XCode targets/schemes and Android flavors. There is experimental support for this in react-native-ultimate-config if you still want to try to use it.

Are you referring to dependencies in native code?

The reason I'm asking is that with recently introduced feature of hooks it's now possible to intercept a moment when env is injected and do some custom operations like: copy assets into asset catalog and similar.

I'm curious to learn about your experience which led to such approach and I am sure it can be handled with rnuc to some extent.

There is experimental support for this in react-native-ultimate-config if you still want to try to use it.

Unfortunately I hit some walls with these features: since they are part of the build process it could be a bit harder to implement certain functionality when project has rnuc as part of schemes/flavors and I am not entirely sure if they will ever get out of "experimental" incubator or even if they will if they will be able to carry all the functionality that CLI does.

Thanks,
Max.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.