Skip to content

Commit f4edf87

Browse files
Merge pull request #25 from Instabug/feature/move-builder-to-bridging-file
Move builder to bridging file & Fix invocation event
2 parents e3be01e + ddde24b commit f4edf87

File tree

4 files changed

+39
-87
lines changed

4 files changed

+39
-87
lines changed

android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
21
package com.instabug.reactlibrary;
32

3+
import android.app.Application;
44
import android.net.Uri;
55

66
import com.facebook.react.bridge.ReactApplicationContext;
@@ -25,20 +25,18 @@
2525
*/
2626
public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
2727

28-
private Instabug mInstabug;
29-
private InstabugInvocationEvent invocationEvent;
30-
28+
//InvocationEvents
3129
private final String INVOCATION_EVENT_NONE = "none";
3230
private final String INVOCATION_EVENT_SHAKE = "shake";
3331
private final String INVOCATION_EVENT_SCREENSHOT = "screenshot";
3432
private final String INVOCATION_EVENT_TWO_FINGERS_SWIPE = "swipe";
3533
private final String INVOCATION_EVENT_FLOATING_BUTTON = "button";
36-
34+
//InvocationModes
3735
private final String INVOCATION_MODE_NEW_BUG = "bug";
3836
private final String INVOCATION_MODE_NEW_FEEDBACK = "feedback";
3937
private final String INVOCATION_MODE_NEW_CHAT = "chat";
4038
private final String INVOCATION_MODE_CHATS_LIST = "chats";
41-
39+
//locales
4240
private final String LOCALE_ARABIC = "arabic";
4341
private final String LOCALE_CHINESE_SIMPLIFIED = "chinesesimplified";
4442
private final String LOCALE_CHINESE_TRADITIONAL = "chinesetraditional";
@@ -56,22 +54,34 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
5654
private final String LOCALE_SWEDISH = "swedish";
5755
private final String LOCALE_TURKISH = "turkish";
5856

57+
private Application androidApplication;
58+
private Instabug mInstabug;
59+
private InstabugInvocationEvent invocationEvent;
60+
5961
/**
6062
* Instantiates a new Rn instabug reactnative module.
6163
*
6264
* @param reactContext the react context
6365
* @param mInstabug the m instabug
6466
*/
65-
public RNInstabugReactnativeModule(ReactApplicationContext reactContext, Instabug mInstabug) {
67+
public RNInstabugReactnativeModule(ReactApplicationContext reactContext, Application androidApplication) {
6668
super(reactContext);
67-
this.mInstabug = mInstabug;
69+
this.androidApplication = androidApplication;
6870
}
6971

7072
@Override
7173
public String getName() {
7274
return "Instabug";
7375
}
7476

77+
@ReactMethod
78+
public void startWithToken(String androidToken, String invocationEvent) {
79+
mInstabug = new Instabug.Builder(this.androidApplication, androidToken)
80+
.setIntroMessageEnabled(false)
81+
.setInvocationEvent(getInvocationEventById(invocationEvent))
82+
.build();
83+
}
84+
7585
/**
7686
* invoke sdk manually
7787
*/
@@ -155,7 +165,6 @@ public void changeLocale(String instabugLocale) {
155165
}
156166
}
157167

158-
159168
/**
160169
* The file at filePath will be uploaded along upcoming reports with the name fileNameWithExtension
161170
*
@@ -394,9 +403,16 @@ public int getUnreadMessagesCount() {
394403
*/
395404
@ReactMethod
396405
public void setInvocationEvent(String invocationEventValue) {
397-
InstabugInvocationEvent invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
398406
try {
399-
//setting invocation event
407+
mInstabug.changeInvocationEvent(getInvocationEventById(invocationEventValue));
408+
} catch (Exception e) {
409+
e.printStackTrace();
410+
}
411+
}
412+
413+
private InstabugInvocationEvent getInvocationEventById(String invocationEventValue) {
414+
InstabugInvocationEvent invocationEvent = InstabugInvocationEvent.SHAKE;
415+
try {
400416
if (invocationEventValue.equals(INVOCATION_EVENT_FLOATING_BUTTON)) {
401417
invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
402418
} else if (invocationEventValue.equals(INVOCATION_EVENT_TWO_FINGERS_SWIPE)) {
@@ -409,11 +425,11 @@ public void setInvocationEvent(String invocationEventValue) {
409425
invocationEvent = InstabugInvocationEvent.NONE;
410426
}
411427

412-
mInstabug.changeInvocationEvent(invocationEvent);
428+
return invocationEvent;
413429
} catch (Exception e) {
414430
e.printStackTrace();
431+
return invocationEvent;
415432
}
416-
417433
}
418434

419435
/**

android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativePackage.java

Lines changed: 9 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
package com.instabug.reactlibrary;
32

43
import android.app.Application;
@@ -10,91 +9,45 @@
109
import com.facebook.react.uimanager.ViewManager;
1110
import com.instabug.library.Instabug;
1211
import com.instabug.library.InstabugColorTheme;
13-
import com.instabug.library.internal.module.InstabugLocale;
1412
import com.instabug.library.invocation.InstabugInvocationEvent;
15-
import com.instabug.library.invocation.util.InstabugFloatingButtonEdge;
1613

1714
import java.util.ArrayList;
1815
import java.util.Collections;
1916
import java.util.List;
20-
import java.util.Locale;
2117

2218
public class RNInstabugReactnativePackage implements ReactPackage {
2319

24-
Application androidApplication;
20+
private Application androidApplication;
2521
private String mAndroidApplicationToken;
2622
private Instabug mInstabug;
2723
private Instabug.Builder mBuilder;
2824
private InstabugInvocationEvent invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
2925
private InstabugColorTheme instabugColorTheme = InstabugColorTheme.InstabugColorThemeLight;
3026

31-
public RNInstabugReactnativePackage(Instabug instabug) {
32-
this.mInstabug = instabug;
27+
public RNInstabugReactnativePackage(Application androidApplication) {
28+
this.androidApplication = androidApplication;
3329
}
3430

31+
@Deprecated
3532
public RNInstabugReactnativePackage(String androidApplicationToken, Application application) {
3633
this(androidApplicationToken, application, "button");
3734
}
3835

39-
public RNInstabugReactnativePackage(String androidApplicationToken, Application application, String invocationEventValue) {
36+
@Deprecated
37+
public RNInstabugReactnativePackage(String androidApplicationToken, Application application
38+
String invocationEventValue) {
4039
this(androidApplicationToken, application, invocationEventValue, "light");
4140
}
4241

42+
@Deprecated
4343
public RNInstabugReactnativePackage(String androidApplicationToken, Application application,
4444
String invocationEventValue, String instabugColorThemeValue) {
45-
46-
this.androidApplication = application;
47-
this.mAndroidApplicationToken = androidApplicationToken;
48-
49-
//setting invocation event
50-
if (invocationEventValue.equals("button")) {
51-
this.invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
52-
} else if (invocationEventValue.equals("swipe")) {
53-
this.invocationEvent = InstabugInvocationEvent.TWO_FINGER_SWIPE_LEFT;
54-
55-
} else if (invocationEventValue.equals("shake")) {
56-
this.invocationEvent = InstabugInvocationEvent.SHAKE;
57-
58-
} else if (invocationEventValue.equals("screenshot")) {
59-
this.invocationEvent = InstabugInvocationEvent.SCREENSHOT_GESTURE;
60-
61-
} else if (invocationEventValue.equals("none")) {
62-
this.invocationEvent = InstabugInvocationEvent.NONE;
63-
64-
} else {
65-
this.invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
66-
}
67-
68-
//setting instabugColorTheme
69-
if (instabugColorThemeValue.equals("light")) {
70-
this.instabugColorTheme = InstabugColorTheme.InstabugColorThemeLight;
71-
} else if (instabugColorThemeValue.equals("dark")) {
72-
this.instabugColorTheme = InstabugColorTheme.InstabugColorThemeDark;
73-
} else {
74-
this.instabugColorTheme = InstabugColorTheme.InstabugColorThemeLight;
75-
}
76-
77-
78-
mInstabug = new Instabug.Builder(this.androidApplication, this.mAndroidApplicationToken)
79-
.setFloatingButtonOffsetFromTop(400)
80-
.setTheme(this.instabugColorTheme)
81-
.setInvocationEvent(this.invocationEvent)
82-
.setIntroMessageEnabled(false)
83-
.setAttachmentTypesEnabled(true, true, true, true, true)
84-
.setShouldPlayConversationSounds(true)
85-
.setEnableInAppNotificationSound(true)
86-
.setEnableSystemNotificationSound(false)
87-
.setPromptOptionsEnabled(true, true, true)
88-
.setWillSkipScreenshotAnnotation(false)
89-
.setFloatingButtonEdge(InstabugFloatingButtonEdge.LEFT)
90-
.setLocale(new Locale(InstabugLocale.ENGLISH.getCode(), InstabugLocale.ENGLISH.getCountry()))
91-
.build();
9245
}
9346

9447
@Override
9548
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
9649
List<NativeModule> modules = new ArrayList<>();
97-
modules.add(new RNInstabugReactnativeModule(reactContext, this.mInstabug));
50+
modules.add(new RNInstabugReactnativeModule(reactContext, this.androidApplication));
9851
return modules;
9952
}
10053

index.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ module.exports = {
2525
* the SDK's UI.
2626
*/
2727
startWithToken: function (token, invocationEvent) {
28-
if (Platform.OS === 'ios')
2928
Instabug.startWithToken(token, invocationEvent);
3029
},
3130

@@ -151,15 +150,6 @@ module.exports = {
151150
}
152151
},
153152

154-
/**
155-
* A callback that gets executed after the SDK's UI is dismissed.
156-
* @callback postInvocationHandler
157-
* @param {dismissType} dismissType How the SDK was dismissed.
158-
* @param {reportType} reportType Type of report that has been sent. Will be set
159-
* to IBGReportTypeBug in case the SDK has been dismissed without selecting a
160-
* report type, so you might need to check issueState before reportType
161-
*/
162-
163153
/**
164154
* Sets a block of code to be executed right after the SDK's UI is dismissed.
165155
* This block is executed on the UI thread. Could be used for performing any
@@ -222,13 +212,6 @@ module.exports = {
222212
}
223213
},
224214

225-
/**
226-
* return callback
227-
* @callback messageCountCallback
228-
* @param{number} responseCount Notifications count, or -1 incase the SDK has
229-
* not been initialized.
230-
*/
231-
232215
/**
233216
* Returns the number of unread messages the user currently has.
234217
* Use this method to get the number of unread messages the user

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"homepage": "https://github.com/Instabug/instabug-reactnative#readme",
2727
"rnpm": {
2828
"android": {
29-
"packageInstance": "new RNInstabugReactnativePackage(\"YOUR_ANDROID_APPLICATION_TOKEN\",MainApplication.this,\"button\")"
29+
"packageInstance": "new RNInstabugReactnativePackage(MainApplication.this)"
3030
}
3131
},
3232
"dependencies": {

0 commit comments

Comments
 (0)