Unfortunately there is no direct way of doing what you ask.
Using Platform
You can define custom code for each application using the Platform react native API, which docs can be found on the RN docs. Using this API you can check the current platform and define code for each.
import { Platform, StyleSheet } from 'react-native';
const styles = StyleSheet.create({ height: (Platform.OS === 'ios') ? 200 : 100, });
or you can also define some code for each platform using platform.select
import { Platform, StyleSheet } from 'react-native';
const styles = StyleSheet.create({
container: {
flex: 1,
...Platform.select({
ios: {
backgroundColor: 'red',
},
android: {
backgroundColor: 'blue',
},
}),
},
Using Specific file extensions
You can name each js file using filename.ios.js or filename.android.js and they will be called in each platform automatically.
Using Environments
Besides of platform in many cases I like to define an Environment module which allows me to swap some values depending on what environment I've selected. For example:
- environment
/environment.js
/state.js
In environment.js I save the available state keys and the currently selected environment:
environment.js
export const environments = {
pre: "PRE_ENV",
prod: "PROD_ENV",
};
export const currentEnvironment = environments.pre;
Then in the state.js I like to store some helpers to check which environment I'm in:
state.js
import { currentEnvironment, environments } from "./environment";
export const isProductionEnvironment = () => {
return environments.prod === currentEnvironment;
};
export const isPreEnvironment = () => {
return environments.pre === currentEnvironment;
};
Now you can make some environment-dependent code in new files, like:
greeting.js
import { environments, currentEnvironment } from "./environment";
export const selectGreeting = () => {
switch(currentEnvironment) {
case environments.pre:
return "Welcome to the pre environment";
case environments.prod:
return "Welcome to the prod environment";
default:
return "Unsupported Environment";
}
};
To manage your app.js there is no beautiful solution, you store some default app.js to some environment and copy paste it or you can use:
https://github.com/oliverbenns/expo-deploy
It is a little library written in bash which helps you deploy to multiple slugs.
Hope it helps!