mirror of
https://github.com/status-im/instabug-reactnative.git
synced 2025-03-03 14:40:54 +00:00
Merge pull request #25 from Instabug/feature/move-builder-to-bridging-file
Move builder to bridging file & Fix invocation event
This commit is contained in:
commit
f4edf879a2
@ -1,6 +1,6 @@
|
||||
|
||||
package com.instabug.reactlibrary;
|
||||
|
||||
import android.app.Application;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
@ -25,20 +25,18 @@ import java.util.Map;
|
||||
*/
|
||||
public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
|
||||
|
||||
private Instabug mInstabug;
|
||||
private InstabugInvocationEvent invocationEvent;
|
||||
|
||||
//InvocationEvents
|
||||
private final String INVOCATION_EVENT_NONE = "none";
|
||||
private final String INVOCATION_EVENT_SHAKE = "shake";
|
||||
private final String INVOCATION_EVENT_SCREENSHOT = "screenshot";
|
||||
private final String INVOCATION_EVENT_TWO_FINGERS_SWIPE = "swipe";
|
||||
private final String INVOCATION_EVENT_FLOATING_BUTTON = "button";
|
||||
|
||||
//InvocationModes
|
||||
private final String INVOCATION_MODE_NEW_BUG = "bug";
|
||||
private final String INVOCATION_MODE_NEW_FEEDBACK = "feedback";
|
||||
private final String INVOCATION_MODE_NEW_CHAT = "chat";
|
||||
private final String INVOCATION_MODE_CHATS_LIST = "chats";
|
||||
|
||||
//locales
|
||||
private final String LOCALE_ARABIC = "arabic";
|
||||
private final String LOCALE_CHINESE_SIMPLIFIED = "chinesesimplified";
|
||||
private final String LOCALE_CHINESE_TRADITIONAL = "chinesetraditional";
|
||||
@ -56,15 +54,19 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
|
||||
private final String LOCALE_SWEDISH = "swedish";
|
||||
private final String LOCALE_TURKISH = "turkish";
|
||||
|
||||
private Application androidApplication;
|
||||
private Instabug mInstabug;
|
||||
private InstabugInvocationEvent invocationEvent;
|
||||
|
||||
/**
|
||||
* Instantiates a new Rn instabug reactnative module.
|
||||
*
|
||||
* @param reactContext the react context
|
||||
* @param mInstabug the m instabug
|
||||
*/
|
||||
public RNInstabugReactnativeModule(ReactApplicationContext reactContext, Instabug mInstabug) {
|
||||
public RNInstabugReactnativeModule(ReactApplicationContext reactContext, Application androidApplication) {
|
||||
super(reactContext);
|
||||
this.mInstabug = mInstabug;
|
||||
this.androidApplication = androidApplication;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -72,6 +74,14 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
|
||||
return "Instabug";
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void startWithToken(String androidToken, String invocationEvent) {
|
||||
mInstabug = new Instabug.Builder(this.androidApplication, androidToken)
|
||||
.setIntroMessageEnabled(false)
|
||||
.setInvocationEvent(getInvocationEventById(invocationEvent))
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* invoke sdk manually
|
||||
*/
|
||||
@ -155,7 +165,6 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The file at filePath will be uploaded along upcoming reports with the name fileNameWithExtension
|
||||
*
|
||||
@ -394,9 +403,16 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
|
||||
*/
|
||||
@ReactMethod
|
||||
public void setInvocationEvent(String invocationEventValue) {
|
||||
InstabugInvocationEvent invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
|
||||
try {
|
||||
//setting invocation event
|
||||
mInstabug.changeInvocationEvent(getInvocationEventById(invocationEventValue));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private InstabugInvocationEvent getInvocationEventById(String invocationEventValue) {
|
||||
InstabugInvocationEvent invocationEvent = InstabugInvocationEvent.SHAKE;
|
||||
try {
|
||||
if (invocationEventValue.equals(INVOCATION_EVENT_FLOATING_BUTTON)) {
|
||||
invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
|
||||
} else if (invocationEventValue.equals(INVOCATION_EVENT_TWO_FINGERS_SWIPE)) {
|
||||
@ -409,11 +425,11 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
|
||||
invocationEvent = InstabugInvocationEvent.NONE;
|
||||
}
|
||||
|
||||
mInstabug.changeInvocationEvent(invocationEvent);
|
||||
return invocationEvent;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return invocationEvent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
package com.instabug.reactlibrary;
|
||||
|
||||
import android.app.Application;
|
||||
@ -10,91 +9,45 @@ import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.uimanager.ViewManager;
|
||||
import com.instabug.library.Instabug;
|
||||
import com.instabug.library.InstabugColorTheme;
|
||||
import com.instabug.library.internal.module.InstabugLocale;
|
||||
import com.instabug.library.invocation.InstabugInvocationEvent;
|
||||
import com.instabug.library.invocation.util.InstabugFloatingButtonEdge;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class RNInstabugReactnativePackage implements ReactPackage {
|
||||
|
||||
Application androidApplication;
|
||||
private Application androidApplication;
|
||||
private String mAndroidApplicationToken;
|
||||
private Instabug mInstabug;
|
||||
private Instabug.Builder mBuilder;
|
||||
private InstabugInvocationEvent invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
|
||||
private InstabugColorTheme instabugColorTheme = InstabugColorTheme.InstabugColorThemeLight;
|
||||
|
||||
public RNInstabugReactnativePackage(Instabug instabug) {
|
||||
this.mInstabug = instabug;
|
||||
public RNInstabugReactnativePackage(Application androidApplication) {
|
||||
this.androidApplication = androidApplication;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public RNInstabugReactnativePackage(String androidApplicationToken, Application application) {
|
||||
this(androidApplicationToken, application, "button");
|
||||
}
|
||||
|
||||
public RNInstabugReactnativePackage(String androidApplicationToken, Application application, String invocationEventValue) {
|
||||
@Deprecated
|
||||
public RNInstabugReactnativePackage(String androidApplicationToken, Application application
|
||||
String invocationEventValue) {
|
||||
this(androidApplicationToken, application, invocationEventValue, "light");
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public RNInstabugReactnativePackage(String androidApplicationToken, Application application,
|
||||
String invocationEventValue, String instabugColorThemeValue) {
|
||||
|
||||
this.androidApplication = application;
|
||||
this.mAndroidApplicationToken = androidApplicationToken;
|
||||
|
||||
//setting invocation event
|
||||
if (invocationEventValue.equals("button")) {
|
||||
this.invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
|
||||
} else if (invocationEventValue.equals("swipe")) {
|
||||
this.invocationEvent = InstabugInvocationEvent.TWO_FINGER_SWIPE_LEFT;
|
||||
|
||||
} else if (invocationEventValue.equals("shake")) {
|
||||
this.invocationEvent = InstabugInvocationEvent.SHAKE;
|
||||
|
||||
} else if (invocationEventValue.equals("screenshot")) {
|
||||
this.invocationEvent = InstabugInvocationEvent.SCREENSHOT_GESTURE;
|
||||
|
||||
} else if (invocationEventValue.equals("none")) {
|
||||
this.invocationEvent = InstabugInvocationEvent.NONE;
|
||||
|
||||
} else {
|
||||
this.invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
|
||||
}
|
||||
|
||||
//setting instabugColorTheme
|
||||
if (instabugColorThemeValue.equals("light")) {
|
||||
this.instabugColorTheme = InstabugColorTheme.InstabugColorThemeLight;
|
||||
} else if (instabugColorThemeValue.equals("dark")) {
|
||||
this.instabugColorTheme = InstabugColorTheme.InstabugColorThemeDark;
|
||||
} else {
|
||||
this.instabugColorTheme = InstabugColorTheme.InstabugColorThemeLight;
|
||||
}
|
||||
|
||||
|
||||
mInstabug = new Instabug.Builder(this.androidApplication, this.mAndroidApplicationToken)
|
||||
.setFloatingButtonOffsetFromTop(400)
|
||||
.setTheme(this.instabugColorTheme)
|
||||
.setInvocationEvent(this.invocationEvent)
|
||||
.setIntroMessageEnabled(false)
|
||||
.setAttachmentTypesEnabled(true, true, true, true, true)
|
||||
.setShouldPlayConversationSounds(true)
|
||||
.setEnableInAppNotificationSound(true)
|
||||
.setEnableSystemNotificationSound(false)
|
||||
.setPromptOptionsEnabled(true, true, true)
|
||||
.setWillSkipScreenshotAnnotation(false)
|
||||
.setFloatingButtonEdge(InstabugFloatingButtonEdge.LEFT)
|
||||
.setLocale(new Locale(InstabugLocale.ENGLISH.getCode(), InstabugLocale.ENGLISH.getCountry()))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
||||
List<NativeModule> modules = new ArrayList<>();
|
||||
modules.add(new RNInstabugReactnativeModule(reactContext, this.mInstabug));
|
||||
modules.add(new RNInstabugReactnativeModule(reactContext, this.androidApplication));
|
||||
return modules;
|
||||
}
|
||||
|
||||
|
17
index.js
17
index.js
@ -25,7 +25,6 @@ module.exports = {
|
||||
* the SDK's UI.
|
||||
*/
|
||||
startWithToken: function (token, invocationEvent) {
|
||||
if (Platform.OS === 'ios')
|
||||
Instabug.startWithToken(token, invocationEvent);
|
||||
},
|
||||
|
||||
@ -151,15 +150,6 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* A callback that gets executed after the SDK's UI is dismissed.
|
||||
* @callback postInvocationHandler
|
||||
* @param {dismissType} dismissType How the SDK was dismissed.
|
||||
* @param {reportType} reportType Type of report that has been sent. Will be set
|
||||
* to IBGReportTypeBug in case the SDK has been dismissed without selecting a
|
||||
* report type, so you might need to check issueState before reportType
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sets a block of code to be executed right after the SDK's UI is dismissed.
|
||||
* This block is executed on the UI thread. Could be used for performing any
|
||||
@ -222,13 +212,6 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* return callback
|
||||
* @callback messageCountCallback
|
||||
* @param{number} responseCount Notifications count, or -1 incase the SDK has
|
||||
* not been initialized.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the number of unread messages the user currently has.
|
||||
* Use this method to get the number of unread messages the user
|
||||
|
@ -26,7 +26,7 @@
|
||||
"homepage": "https://github.com/Instabug/instabug-reactnative#readme",
|
||||
"rnpm": {
|
||||
"android": {
|
||||
"packageInstance": "new RNInstabugReactnativePackage(\"YOUR_ANDROID_APPLICATION_TOKEN\",MainApplication.this,\"button\")"
|
||||
"packageInstance": "new RNInstabugReactnativePackage(MainApplication.this)"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user