Create instabug-reactnative

This commit is contained in:
DevHossamHassan
2016-10-05 21:05:34 +02:00
parent 948b9a8713
commit 866dc12bb9
20 changed files with 398 additions and 580 deletions
@@ -0,0 +1,165 @@
package com.instabug.reactlibrary;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;
import com.instabug.library.IBGInvocationMode;
import com.instabug.library.Instabug;
import java.util.Locale;
import android.net.Uri;
public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
private Instabug mInstabug;
public RNInstabugReactnativeModule(ReactApplicationContext reactContext, Instabug instabug) {
super(reactContext);
this.mInstabug = instabug;
}
@Override
public String getName() {
return "RNInstabugReactnative";
}
/**
* Adds tag(s) to issues before sending them
*
* @param tags
*/
@ReactMethod
public void addTags(String tags) {
try {
String[] result = tags.split(",");
mInstabug.resetTags(); //clear last commit tags
mInstabug.addTags(result);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Change Locale of Instabug UI elements(defaults to English)
*
* @param languageTag
*/
@ReactMethod
public void changeLocale(String languageTag) {
try {
switch (languageTag) {
case "CHINA":
case "CHINESE":
case "PRC":
case "SIMPLIFIED_CHINESE":
mInstabug.changeLocale(Locale.CHINESE);
break;
case "TAIWAN":
case "TRADITIONAL_CHINESE":
mInstabug.changeLocale(Locale.TAIWAN);
break;
case "ENGLISH":
mInstabug.changeLocale(Locale.ENGLISH);
break;
case "UK":
mInstabug.changeLocale(Locale.UK);
break;
case "US":
mInstabug.changeLocale(Locale.US);
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
@ReactMethod
public void report(String value) {
IBGInvocationMode mode = IBGInvocationMode.IBGInvocationModeNA;
if (value.equals("bug")) {
mode = IBGInvocationMode.IBGInvocationModeBugReporter;
} else if (value.equals("feedback")) {
mode = IBGInvocationMode.IBGInvocationModeFeedbackSender;
}
mInstabug.invoke(mode);
}
/**
* The file at filePath will be uploaded along upcoming reports with the name fileNameWithExtension
*
* @param fileUri
* @param fileNameWithExtension
*/
@ReactMethod
public void setFileAttachment(String fileUri, String fileNameWithExtension) {
try {
Uri uri = Uri.parse(fileUri);
mInstabug.setFileAttachment(uri, fileNameWithExtension);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* If your app already acquires the user's email address and you provide it to this method,
* Instabug will pre-fill the user email in reports.
*
* @param userEmail
*/
@ReactMethod
public void setUserEmail(String userEmail) {
try {
mInstabug.setUserEmail(userEmail);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Sets the user name that is used in the dashboard's contacts.
*
* @param username
*/
@ReactMethod
public void setUsername(String username) {
try {
mInstabug.setUsername(username);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Adds specific user data that you need to be added to the reports
*
* @param userData
*/
@ReactMethod
public void setUserData(String userData) {
try {
mInstabug.setUserData(userData);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Call this method to display the discovery dialog explaining the shake gesture or the two
* finger swipe gesture, if you've enabled it.
* i.e: This method is automatically called on first run of the application
*/
@ReactMethod
public void showIntroMessage() {
try {
mInstabug.showIntroMessage();
} catch (Exception e) {
e.printStackTrace();
}
}
}
@@ -0,0 +1,67 @@
package com.instabug.reactlibrary;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import android.app.Application;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.bridge.JavaScriptModule;
import com.instabug.library.IBGColorTheme;
import com.instabug.library.IBGInvocationEvent;
import com.instabug.library.Instabug;
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(IBGColorTheme.IBGColorThemeDark)
.setInvocationEvent(IBGInvocationEvent.IBGInvocationEventFloatingButton)
.setShouldShowIntroDialog(false)
//.setInvocationEvent(IBGInvocationEvent.IBGInvocationEventShake)
.build();
}
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new RNInstabugReactnativeModule(reactContext, this.mInstagbug));
return modules;
}
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
@@ -1,22 +0,0 @@
package com.reactlibrary;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;
public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
private final ReactApplicationContext reactContext;
public RNInstabugReactnativeModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
}
@Override
public String getName() {
return "RNInstabugReactnative";
}
}
@@ -1,28 +0,0 @@
package com.reactlibrary;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.bridge.JavaScriptModule;
public class RNInstabugReactnativePackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(new RNInstabugReactnativeModule(reactContext));
}
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}