Skip to content

Commit 5c255c1

Browse files
Enable setting Theme Color in android
1 parent 57f7163 commit 5c255c1

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.instabug.library.internal.module.InstabugLocale;
1414
import com.instabug.library.invocation.InstabugInvocationEvent;
1515
import com.instabug.library.invocation.InstabugInvocationMode;
16+
import com.instabug.library.InstabugColorTheme;
1617
import com.instabug.library.logging.InstabugLog;
1718
import com.instabug.library.bugreporting.model.ReportCategory;
1819

@@ -56,6 +57,10 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
5657
private final String LOCALE_SWEDISH = "swedish";
5758
private final String LOCALE_TURKISH = "turkish";
5859

60+
//Theme colors
61+
private final String COLOR_THEME_LIGHT = "light";
62+
private final String COLOR_THEME_DARK = "dark";
63+
5964
private Application androidApplication;
6065
private Instabug mInstabug;
6166
private InstabugInvocationEvent invocationEvent;
@@ -627,6 +632,25 @@ public void clearAllUserAttributes() {
627632
}
628633
}
629634

635+
/**
636+
* Sets InstabugSDK theme color.
637+
*
638+
* @param theme which is a constant String "light" or "dark"
639+
*/
640+
@ReactMethod
641+
public void setColorTheme(String theme) {
642+
try {
643+
if (theme.equals(COLOR_THEME_LIGHT)) {
644+
mInstabug.setTheme(InstabugColorTheme.InstabugColorThemeLight);
645+
646+
} else if (theme.equals(COLOR_THEME_DARK)) {
647+
mInstabug.setTheme(InstabugColorTheme.InstabugColorThemeDark);
648+
}
649+
} catch (Exception e) {
650+
e.printStackTrace();
651+
}
652+
}
653+
630654
/**
631655
* Allows you to show a predefined set of categories for users to choose
632656
* from when reporting a bug or sending feedback. Selected category
@@ -642,7 +666,8 @@ public void setReportCategories(ReadableArray categoriesTitles) {
642666
int size = categoriesTitles != null ? categoriesTitles.size() : 0;
643667
if (size == 0) return;
644668
for (int i = 0; i < size; i++) {
645-
bugCategories.add(ReportCategory.getInstance().withLabel(categoriesTitles.getString(i)));
669+
bugCategories.add(ReportCategory.getInstance().withLabel(categoriesTitles
670+
.getString(i)));
646671
}
647672

648673
Instabug.setReportCategories(bugCategories);
@@ -717,6 +742,9 @@ public Map<String, Object> getConstants() {
717742
constants.put("invocationEventTwoFingersSwipe", INVOCATION_EVENT_TWO_FINGERS_SWIPE);
718743
constants.put("invocationEventFloatingButton", INVOCATION_EVENT_FLOATING_BUTTON);
719744

745+
constants.put("colorThemeLight", COLOR_THEME_LIGHT);
746+
constants.put("colorThemeDark", COLOR_THEME_DARK);
747+
720748
constants.put("invocationModeNewBug", INVOCATION_MODE_NEW_BUG);
721749
constants.put("invocationModeNewFeedback", INVOCATION_MODE_NEW_FEEDBACK);
722750
constants.put("invocationModeNewChat", INVOCATION_MODE_NEW_CHAT);

index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,7 @@ module.exports = {
311311
* @param colorTheme
312312
*/
313313
setColorTheme: function (colorTheme) {
314-
if (Platform.OS === 'ios')
315-
Instabug.setColorTheme(colorTheme);
314+
Instabug.setColorTheme(colorTheme);
316315
},
317316

318317
/**
@@ -458,7 +457,7 @@ module.exports = {
458457
* to. Selected category will be shown as a tag on your dashboard.
459458
* @param {array} titles titles to be shown in the list.
460459
*/
461-
setReportCategories: function (... titles) {
460+
setReportCategories: function (...titles) {
462461
if (Platform.OS == 'ios') {
463462
Instabug.setReportCategories(titles, null);
464463
} else if (Platform.OS == 'android') {

0 commit comments

Comments
 (0)