Add startWithTokenForAndroid to index.js

This commit is contained in:
DevHossamHassan 2016-10-17 19:58:43 +02:00
parent eb6401cac5
commit 3ccbfdf60a
3 changed files with 61 additions and 34 deletions

View File

@ -5,7 +5,8 @@ import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback; import com.facebook.react.bridge.Callback;
import com.instabug.library.InstabugColorTheme;
import com.instabug.library.InstabugInvocationEvent;
import com.instabug.library.InstabugInvocationMode; import com.instabug.library.InstabugInvocationMode;
import com.instabug.library.Instabug; import com.instabug.library.Instabug;
@ -16,10 +17,13 @@ import android.net.Uri;
public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule { public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
private Instabug mInstabug; private Instabug mInstabug;
private String mAndroidApplicationToken;
private Instabug.Builder mBuilder;
private Application mApplication;
public RNInstabugReactnativeModule(ReactApplicationContext reactContext, Instabug instabug) { public RNInstabugReactnativeModule(ReactApplicationContext reactContext) {
super(reactContext); super(reactContext);
this.mInstabug = instabug; this.mApplication = reactContext;
} }
@Override @Override
@ -27,6 +31,26 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
return "RNInstabugReactnative"; return "RNInstabugReactnative";
} }
/**
* start Instabug with default opetions
* default Invocation event Floating button
* @param androidApplicationToken
*/
@ReactMethod
public void startInstabugWithTokenForAndroid(String androidApplicationToken)
{
this.mAndroidApplicationToken = androidApplicationToken;
mInstagbug = new Instabug.Builder(mApplication, mAndroidApplicationToken)
.setDebugEnabled(true)
.setEmailFieldRequired(false)
.setFloatingButtonOffsetFromTop(400)
.setColorTheme(InstabugColorTheme.InstabugColorThemeLight)
.setInvocationEvent(InstabugInvocationEvent.InstabugInvocationEventFloatingButton)
.setShouldShowIntroDialog(false)
.build();
}
/** /**
* Adds tag(s) to issues before sending them * Adds tag(s) to issues before sending them
* *

View File

@ -19,39 +19,10 @@ import com.instabug.library.Instabug;
public class RNInstabugReactnativePackage implements ReactPackage { public class RNInstabugReactnativePackage implements ReactPackage {
private String mToken;
private Application mApplication;
private Instabug mInstagbug;
private Instabug.Builder mBuilder;
public RNInstabugReactnativePackage(Instabug instabug) {
this.mInstagbug = instabug;
}
public RNInstabugReactnativePackage(Instabug.Builder builder) {
this.mBuilder = builder;
}
public RNInstabugReactnativePackage(String token, Application application) {
this.mToken = token;
this.mApplication = application;
mInstagbug = new Instabug.Builder(mApplication, mToken)
.setDebugEnabled(true)
.setEmailFieldRequired(false)
.setFloatingButtonOffsetFromTop(400)
.setColorTheme(InstabugColorTheme.InstabugColorThemeDark)
.setInvocationEvent(InstabugInvocationEvent.InstabugInvocationEventFloatingButton)
.setShouldShowIntroDialog(false)
//.setInvocationEvent(InstabugInvocationEvent.InstabugInvocationEventShake)
.build();
}
@Override @Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) { public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>(); List<NativeModule> modules = new ArrayList<>();
modules.add(new RNInstabugReactnativeModule(reactContext, this.mInstagbug)); modules.add(new RNInstabugReactnativeModule(reactContext));
return modules; return modules;
} }

View File

@ -14,13 +14,45 @@ module.exports = {
* This is the main SDK method that does all the magic. This is the only * This is the main SDK method that does all the magic. This is the only
* method that SHOULD be called. * method that SHOULD be called.
* Should be called in constructor of the app registery component * Should be called in constructor of the app registery component
* @param {string} androidToken The token that identifies the app, you can find
* it on your dashboard.
* @param {string} iosToken The token that identifies the app, you can find
* it on your dashboard.
* @param {constants.invocationEvent} invocationEvent The event that invokes
* the SDK's UI.
*/
startWithToken: function(androidToken,iosToken, invocationEvent) {
if( Platform.OS === 'ios') {
Instabug.startWithToken(iosToken, invocationEvent);
} else {
Instabug.startInstabugWithTokenForAndroid(androidToken);
}
},
/**
* Starts the SDK.
* This is the main SDK method that does all the magic. This is the only
* method that SHOULD be called.
* Should be called in constructor of the app registery component
* @param {string} token The token that identifies the app, you can find * @param {string} token The token that identifies the app, you can find
* it on your dashboard. * it on your dashboard.
* @param {constants.invocationEvent} invocationEvent The event that invokes * @param {constants.invocationEvent} invocationEvent The event that invokes
* the SDK's UI. * the SDK's UI.
*/ */
startWithToken: function(token, invocationEvent) { startWithToken: function(token, invocationEvent) {
if( Platform.OS === 'ios') {
Instabug.startWithToken(token, invocationEvent); Instabug.startWithToken(token, invocationEvent);
} else {
Instabug.startInstabugWithTokenForAndroid(token);
}
}, },
/** /**