React Native wrapper over LaunchDarkly SDK's for iOS and Android.
$ npm install launch-darkly-react-native --save
or
$ yarn add launch-darkly-react-native --save
$ react-native link launch-darkly-react-native
Add the following line to your podfile:
pod 'LaunchDarkly'
and run
pod install
/!\ The Android project has not been updated from the original fork and has not been tested yet!
Add line bellow at the bottom of your app/build.gradle
configurations.all { resolutionStrategy.force 'com.squareup.okhttp3:okhttp:3.4.1' }
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜launch-darkly-react-native
and addRNLaunchDarkly.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNLaunchDarkly.a
to your project'sBuild Phases
➜Link Binary With Libraries
/!\ The Android project has not been updated from the original fork and has not been tested yet!
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.reactlibrary.RNLaunchDarklyPackage;
to the imports at the top of the file - Add
new RNLaunchDarklyPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':launch-darkly-react-native' project(':launch-darkly-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/launch-darkly-react-native/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':launch-darkly-react-native')
- Add line bellow at the bottom of your app/build.gradle
configurations.all { resolutionStrategy.force 'com.squareup.okhttp3:okhttp:3.4.1' }
import LaunchDarkly from 'launch-darkly-react-native';
const user = {
key: 'key',
email: '[email protected]', // optional
firstName: 'firstname', // optional
lastName: 'lastname', // optional
isAnonymous: false, // optional
};
// init native SDK with api key and user object
LaunchDarkly.configure('apiKey', user);
// get boolean feature flag value
LaunchDarkly.boolVariation('featureFlagName', (showFeature) => {
console.log('Show feature:', showFeature);
});
// get string feature flag value
LaunchDarkly.stringVariation('featureFlagName', 'fallback', (value) => {
console.log('String value:', value);
});
// adds listener which is called every time given feature flag value is changed
// callback is called with flagName string, so you will have to call LaunchDarkly.boolVariation()
// to get new feature flag value
LaunchDarkly.addFeatureFlagChangeListener('flagName', () => {
console.log('callback');
});
// removes all onFeatureFlagChange listeners
LaunchDarkly.unsubscribe();