react-native-fabric
A React Native library for Fabric, Crashlytics and Answers`
Installation
npm install react-native-fabric
- Set up Fabric / Crashlytics in your app as instructed on Fabric.io
iOS
- Open your project in Xcode.
- Drag the folder
ReactNativeFabric
from/node_modules/react-native-fabric/ios
into theLibraries
group in the Project navigator. Ensure thatCopy items if needed
is UNCHECKED!
Android
*Note: Android support requires React Native 0.16 or later
-
Edit
android/settings.gradle
to look like this (without the +):rootProject.name = 'MyApp' include ':app' + include ':react-native-fabric' + project(':react-native-fabric').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fabric/android')
-
Edit
android/app/build.gradle
(note: app folder) to look like this:apply plugin: 'com.android.application' android { ... } dependencies { compile 'com.android.support:appcompat-v7:23.0.0' compile 'com.facebook.react:react-native:0.18.+' + compile project(':react-native-fabric') }
-
Edit your
MainActivity.java
(deep inandroid/app/src/main/java/...
) to look like this (note two places to edit):package com.myapp; + import com.smixx.fabric.FabricPackage; .... public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler { private ReactInstanceManager mReactInstanceManager; private ReactRootView mReactRootView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mReactRootView = new ReactRootView(this); mReactInstanceManager = ReactInstanceManager.builder() .setApplication(getApplication()) .setBundleAssetName("index.android.bundle") .setJSMainModuleName("index.android") .addPackage(new MainReactPackage()) + .addPackage(new FabricPackage(this)) .setUseDeveloperSupport(BuildConfig.DEBUG) .setInitialLifecycleState(LifecycleState.RESUMED) .build(); mReactRootView.startReactApplication(mReactInstanceManager, "MyApp", null); setContentView(mReactRootView); } ... }
Crashlytics Usage
To see all available methods take a look at Crashlytics.js
var Fabric = require('react-native-fabric');
var { Crashlytics } = Fabric;
Crashlytics.setUserName('megaman');
Crashlytics.setUserEmail('[email protected]');
Crashlytics.setUserIdentifier('1234');
Crashlytics.setBool('has_posted', true);
Crashlytics.setString('organization', 'Acme. Corp');
// Forces a native crash for testing
Crashlytics.crash();
// Due to differences in primitive types between iOS and Android I've exposed a setNumber function vs. setInt, setFloat, setDouble, setLong, etc
Crashlytics.setNumber('post_count', 5);
Answers Usage
To see all available function take a look at Answers.js
var Fabric = require('react-native-fabric');
var { Answers } = Fabric;
// All log functions take an optional array of custom attributes as the last parameter
Answers.logCustom('Performed a custom event', { bigData: true });
Answers.logAddToCart(24.50, 'USD', 'Air Jordans', 'shoes', '987654', {color: 'red'});
Answers.logInvite('Facebook');
Answers.logLogin('Twitter', true);
Answers.logSearch('React Native');
Answers.logShare('Twitter', 'Big news article', 'post', '1234');
Answers.logSignUp('Twitter', true);
Answers.logPurchase(24.99,'USD',true, 'Air Jordans', 'shoes', '987654');
License
MIT © Cory Smith 2016