Skip to content

Commit c24f16b

Browse files
Merge pull request #35 from Instabug/feature/update-reactnative
Feature/update reactnative
2 parents 70c0f52 + 36e99be commit c24f16b

File tree

3 files changed

+83
-66
lines changed

3 files changed

+83
-66
lines changed

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

Lines changed: 77 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
import com.facebook.react.bridge.ReactMethod;
99
import com.facebook.react.bridge.ReadableArray;
1010
import com.facebook.react.bridge.ReadableMap;
11+
1112
import com.instabug.library.Instabug;
1213
import com.instabug.library.internal.module.InstabugLocale;
1314
import com.instabug.library.invocation.InstabugInvocationEvent;
1415
import com.instabug.library.invocation.InstabugInvocationMode;
1516
import com.instabug.library.logging.InstabugLog;
17+
import com.instabug.library.bugreporting.model.ReportCategory;
1618

1719
import java.util.ArrayList;
1820
import java.util.HashMap;
@@ -64,7 +66,8 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
6466
* @param reactContext the react context
6567
* @param mInstabug the m instabug
6668
*/
67-
public RNInstabugReactnativeModule(ReactApplicationContext reactContext, Application androidApplication) {
69+
public RNInstabugReactnativeModule(ReactApplicationContext reactContext, Application
70+
androidApplication) {
6871
super(reactContext);
6972
this.androidApplication = androidApplication;
7073
}
@@ -166,7 +169,8 @@ public void changeLocale(String instabugLocale) {
166169
}
167170

168171
/**
169-
* The file at filePath will be uploaded along upcoming reports with the name fileNameWithExtension
172+
* The file at filePath will be uploaded along upcoming reports with the name
173+
* fileNameWithExtension
170174
*
171175
* @param fileUri the file uri
172176
* @param fileNameWithExtension the file name with extension
@@ -204,7 +208,7 @@ public void setUserEmail(String userEmail) {
204208
@ReactMethod
205209
public void setUserName(String username) {
206210
try {
207-
mInstabug.setUserName(username);
211+
mInstabug.setUsername(username);
208212
} catch (Exception e) {
209213
e.printStackTrace();
210214
}
@@ -242,7 +246,8 @@ public void showIntroMessage() {
242246
* Set the primary color that the SDK will use to tint certain UI elements in the SDK
243247
*
244248
* @param primaryColorValue The value of the primary color ,
245-
* whatever this color was parsed from a resource color or hex color or RGB color values
249+
* whatever this color was parsed from a resource color or hex color
250+
* or RGB color values
246251
*/
247252
@ReactMethod
248253
public void setPrimaryColor(int primaryColor) {
@@ -263,9 +268,11 @@ public void setPrimaryColor(int primaryColor) {
263268
* @param {boolean} screenRecording A boolean to enable or disable screen recording attachments.
264269
*/
265270
@ReactMethod
266-
public void setAttachmentTypesEnabled(boolean screenshot, boolean extraScreenshot, boolean galleryImage, boolean voiceNote, boolean screenRecording) {
271+
public void setAttachmentTypesEnabled(boolean screenshot, boolean extraScreenshot, boolean
272+
galleryImage, boolean voiceNote, boolean screenRecording) {
267273
try {
268-
mInstabug.setAttachmentTypesEnabled(screenshot, extraScreenshot, galleryImage, voiceNote, screenRecording);
274+
mInstabug.setAttachmentTypesEnabled(screenshot, extraScreenshot, galleryImage,
275+
voiceNote, screenRecording);
269276
} catch (Exception e) {
270277
e.printStackTrace();
271278
}
@@ -274,8 +281,10 @@ public void setAttachmentTypesEnabled(boolean screenshot, boolean extraScreensho
274281
/**
275282
* Appends a log message to Instabug internal log
276283
* <p>
277-
* These logs are then sent along the next uploaded report. All log messages are timestamped <br/>
278-
* Logs aren't cleared per single application run. If you wish to reset the logs, use {@link #clearLog()}
284+
* These logs are then sent along the next uploaded report. All log messages are timestamped
285+
* <br/>
286+
* Logs aren't cleared per single application run. If you wish to reset the logs, use
287+
* {@link #clearLog()}
279288
* </p>
280289
* Note: logs passed to this method are <b>NOT</b> printed to Logcat
281290
*
@@ -478,7 +487,8 @@ public void reportJsException(ReadableArray stack, String message, String errorI
478487
String fileName = frame.getString("file");
479488
int lineNumber = frame.getInt("lineNumber");
480489

481-
stackTraceElements[i] = new StackTraceElement(fileName, methodName, fileName, lineNumber);
490+
stackTraceElements[i] = new StackTraceElement(fileName, methodName, fileName,
491+
lineNumber);
482492
}
483493
Throwable throwable = new Throwable(message);
484494
throwable.setStackTrace(stackTraceElements);
@@ -617,43 +627,84 @@ public void clearAllUserAttributes() {
617627
}
618628
}
619629

630+
/**
631+
* Allows you to show a predefined set of categories for users to choose
632+
* from when reporting a bug or sending feedback. Selected category
633+
* shows up on your Instabug dashboard as a tag to make filtering
634+
* through issues easier.
635+
*
636+
* @param reportCategories the report categories list which is a list of ReportCategory model
637+
*/
638+
@ReactMethod
639+
public void setReportCategories(ReadableArray categoriesTitles) {
640+
try {
641+
ArrayList<ReportCategory> bugCategories = new ArrayList<>();
642+
int size = categoriesTitles != null ? categoriesTitles.size() : 0;
643+
if (size == 0) return;
644+
for (int i = 0; i < size; i++) {
645+
bugCategories.add(ReportCategory.getInstance().withLabel(categoriesTitles.getString(i)));
646+
}
647+
648+
Instabug.setReportCategories(bugCategories);
649+
} catch (Exception e) {
650+
e.printStackTrace();
651+
}
652+
}
653+
620654
private Locale getLocaleByKey(String instabugLocale) {
621655
String localeInLowerCase = instabugLocale.toLowerCase();
622656
switch (localeInLowerCase) {
623657
case LOCALE_ARABIC:
624-
return new Locale(InstabugLocale.ARABIC.getCode(), InstabugLocale.ARABIC.getCountry());
658+
return new Locale(InstabugLocale.ARABIC.getCode(), InstabugLocale.ARABIC
659+
.getCountry());
625660
case LOCALE_ENGLISH:
626-
return new Locale(InstabugLocale.ENGLISH.getCode(), InstabugLocale.ENGLISH.getCountry());
661+
return new Locale(InstabugLocale.ENGLISH.getCode(), InstabugLocale.ENGLISH
662+
.getCountry());
627663
case LOCALE_CZECH:
628-
return new Locale(InstabugLocale.CZECH.getCode(), InstabugLocale.CZECH.getCountry());
664+
return new Locale(InstabugLocale.CZECH.getCode(), InstabugLocale.CZECH.getCountry
665+
());
629666
case LOCALE_FRENCH:
630-
return new Locale(InstabugLocale.FRENCH.getCode(), InstabugLocale.FRENCH.getCountry());
667+
return new Locale(InstabugLocale.FRENCH.getCode(), InstabugLocale.FRENCH
668+
.getCountry());
631669
case LOCALE_GERMAN:
632-
return new Locale(InstabugLocale.GERMAN.getCode(), InstabugLocale.GERMAN.getCountry());
670+
return new Locale(InstabugLocale.GERMAN.getCode(), InstabugLocale.GERMAN
671+
.getCountry());
633672
case LOCALE_ITALIAN:
634-
return new Locale(InstabugLocale.ITALIAN.getCode(), InstabugLocale.ITALIAN.getCountry());
673+
return new Locale(InstabugLocale.ITALIAN.getCode(), InstabugLocale.ITALIAN
674+
.getCountry());
635675
case LOCALE_JAPANESE:
636-
return new Locale(InstabugLocale.JAPANESE.getCode(), InstabugLocale.JAPANESE.getCountry());
676+
return new Locale(InstabugLocale.JAPANESE.getCode(), InstabugLocale.JAPANESE
677+
.getCountry());
637678
case LOCALE_POLISH:
638-
return new Locale(InstabugLocale.POLISH.getCode(), InstabugLocale.POLISH.getCountry());
679+
return new Locale(InstabugLocale.POLISH.getCode(), InstabugLocale.POLISH
680+
.getCountry());
639681
case LOCALE_RUSSIAN:
640-
return new Locale(InstabugLocale.RUSSIAN.getCode(), InstabugLocale.RUSSIAN.getCountry());
682+
return new Locale(InstabugLocale.RUSSIAN.getCode(), InstabugLocale.RUSSIAN
683+
.getCountry());
641684
case LOCALE_SPANISH:
642-
return new Locale(InstabugLocale.SPANISH.getCode(), InstabugLocale.SPANISH.getCountry());
685+
return new Locale(InstabugLocale.SPANISH.getCode(), InstabugLocale.SPANISH
686+
.getCountry());
643687
case LOCALE_SWEDISH:
644-
return new Locale(InstabugLocale.SWEDISH.getCode(), InstabugLocale.SWEDISH.getCountry());
688+
return new Locale(InstabugLocale.SWEDISH.getCode(), InstabugLocale.SWEDISH
689+
.getCountry());
645690
case LOCALE_TURKISH:
646-
return new Locale(InstabugLocale.TURKISH.getCode(), InstabugLocale.TURKISH.getCountry());
691+
return new Locale(InstabugLocale.TURKISH.getCode(), InstabugLocale.TURKISH
692+
.getCountry());
647693
case LOCALE_PORTUGUESE_BRAZIL:
648-
return new Locale(InstabugLocale.PORTUGUESE_BRAZIL.getCode(), InstabugLocale.PORTUGUESE_BRAZIL.getCountry());
694+
return new Locale(InstabugLocale.PORTUGUESE_BRAZIL.getCode(), InstabugLocale
695+
.PORTUGUESE_BRAZIL.getCountry());
649696
case LOCALE_CHINESE_SIMPLIFIED:
650-
return new Locale(InstabugLocale.SIMPLIFIED_CHINESE.getCode(), InstabugLocale.SIMPLIFIED_CHINESE.getCountry());
697+
return new Locale(InstabugLocale.SIMPLIFIED_CHINESE.getCode(), InstabugLocale
698+
.SIMPLIFIED_CHINESE.getCountry());
651699
case LOCALE_CHINESE_TRADITIONAL:
652-
return new Locale(InstabugLocale.TRADITIONAL_CHINESE.getCode(), InstabugLocale.TRADITIONAL_CHINESE.getCountry());
700+
return new Locale(InstabugLocale.TRADITIONAL_CHINESE.getCode(), InstabugLocale
701+
.TRADITIONAL_CHINESE.getCountry());
653702
case LOCALE_KOREAN:
654-
return new Locale(InstabugLocale.KOREAN.getCode(), InstabugLocale.KOREAN.getCountry());
703+
return new Locale(InstabugLocale.KOREAN.getCode(), InstabugLocale.KOREAN
704+
.getCountry());
655705
default:
656-
return new Locale(InstabugLocale.ENGLISH.getCode(), InstabugLocale.ENGLISH.getCountry());
706+
return new Locale(InstabugLocale.ENGLISH.getCode(), InstabugLocale.ENGLISH
707+
.getCountry());
657708
}
658709
}
659710

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public RNInstabugReactnativePackage(String androidApplicationToken, Application
3434
}
3535

3636
@Deprecated
37-
public RNInstabugReactnativePackage(String androidApplicationToken, Application application
37+
public RNInstabugReactnativePackage(String androidApplicationToken, Application application,
3838
String invocationEventValue) {
3939
this(androidApplicationToken, application, invocationEventValue, "light");
4040
}

index.js

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {NativeModules, NativeAppEventEmitter, Platform} from 'react-native';
1+
import {NativeModules, NativeAppEventEmitter, Platform} from "react-native";
22
let {Instabug} = NativeModules;
33

44
/**
@@ -18,7 +18,7 @@ module.exports = {
1818
* the SDK's UI.
1919
*/
2020
startWithToken: function (token, invocationEvent) {
21-
Instabug.startWithToken(token, invocationEvent);
21+
Instabug.startWithToken(token, invocationEvent);
2222
},
2323

2424
/**
@@ -94,11 +94,6 @@ module.exports = {
9494
Instabug.setUserStepsEnabled(isUserStepsEnabled);
9595
},
9696

97-
/**
98-
* A callback that gets executed before sending each bug report.
99-
* @callback preSendingHandler
100-
*/
101-
10297
/**
10398
* Sets a block of code to be executed before sending each report.
10499
* This block is executed in the background before sending each report. Could
@@ -118,13 +113,6 @@ module.exports = {
118113
}
119114
},
120115

121-
/**
122-
* Sets a block of code to be executed just before the SDK's UI is presented.
123-
* This block is executed on the UI thread. Could be used for performing any
124-
* UI changes before the SDK's UI is shown.
125-
* @callback preSendingHandler
126-
*/
127-
128116
/**
129117
* Sets a block of code to be executed just before the SDK's UI is presented.
130118
* This block is executed on the UI thread. Could be used for performing any
@@ -408,11 +396,6 @@ module.exports = {
408396
Instabug.setChatNotificationEnabled(isChatNotificationEnabled);
409397
},
410398

411-
/**
412-
* A callback that gets executed when a new message is received.
413-
* @callback onNewMessgaeHandler
414-
*/
415-
416399
/**
417400
* Sets a block of code that gets executed when a new message is received.
418401
* @param {onNewMessgaeHandler} onNewMessageHandler - A callback that gets
@@ -447,12 +430,6 @@ module.exports = {
447430
Instabug.setPromptOptions(isBugReportingEnabled, isFeedbackReportingEnabled, isChatEnabled);
448431
},
449432

450-
/**
451-
* return callback
452-
* @callback isInstabugNotificationCallback
453-
* @param {boolean} isInstabugNotification
454-
*/
455-
456433
/**
457434
* Checks if a notification is from Instabug.
458435
* If you are using push notifications, use this method to check whether an
@@ -519,11 +496,12 @@ module.exports = {
519496
* Use this method to give users a list of choices of categories their bug report or feedback might be related
520497
* to. Selected category will be shown as a tag on your dashboard.
521498
* @param {array} titles titles to be shown in the list.
522-
* @param {array} name names of icons to be shown along with titles. Use the same names you would use
523499
*/
524-
setReportCategories: function (titles) {
500+
setReportCategories: function (... titles) {
525501
if (Platform.OS == 'ios') {
526502
Instabug.setReportCategories(titles, null);
503+
} else if (Platform.OS == 'android') {
504+
Instabug.setReportCategories(titles);
527505
}
528506
},
529507

@@ -714,12 +692,6 @@ module.exports = {
714692
}
715693
},
716694

717-
/**
718-
* return callback
719-
* @callback userAttributeCallback
720-
* @param {string} value for key in user attributes.
721-
*/
722-
723695
/**
724696
* Returns the user attribute associated with a given key.
725697
aKey
@@ -746,12 +718,6 @@ module.exports = {
746718
}
747719
},
748720

749-
/**
750-
* return callback
751-
* @callback userAttributesCallback
752-
* @param{Object} userAttributes Dictionary of the user attributes.
753-
*/
754-
755721
/**
756722
* @summary Returns all user attributes.
757723
* @param {userAttributesCallback} userAttributesCallback callback with argument A new dictionary containing all the currently set user attributes,

0 commit comments

Comments
 (0)