Skip to content

Commit 3271107

Browse files
committed
📝 Fix setEnabled Api on Android
1 parent a5ee71d commit 3271107

File tree

1 file changed

+60
-26
lines changed

1 file changed

+60
-26
lines changed

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

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.instabug.featuresrequest.ActionType;
3333
import com.instabug.library.Feature;
3434
import com.instabug.library.Instabug;
35+
import com.instabug.library.InstabugState;
3536
import com.instabug.library.OnSdkDismissCallback;
3637
import com.instabug.library.extendedbugreport.ExtendedBugReport;
3738
import com.instabug.library.internal.module.InstabugLocale;
@@ -471,9 +472,9 @@ public void sendHandledJSCrash(String exceptionObject) {
471472
public void setCrashReportingEnabled(boolean isEnabled) {
472473
try {
473474
if (isEnabled) {
474-
Instabug.setCrashReportingState(Feature.State.ENABLED);
475+
CrashReporting.setState(Feature.State.ENABLED);
475476
} else {
476-
Instabug.setCrashReportingState(Feature.State.DISABLED);
477+
CrashReporting.setState(Feature.State.DISABLED);
477478
}
478479
} catch (Exception e) {
479480
e.printStackTrace();
@@ -608,11 +609,16 @@ public boolean isEnabled() {
608609
*/
609610
@ReactMethod
610611
public void enable() {
611-
try {
612-
mInstabug.enable();
613-
} catch (Exception e) {
614-
e.printStackTrace();
615-
}
612+
new Handler(Looper.getMainLooper()).post(new Runnable() {
613+
@Override
614+
public void run() {
615+
try {
616+
Instabug.setState(InstabugState.ENABLED);
617+
} catch (Exception e) {
618+
e.printStackTrace();
619+
}
620+
}
621+
});
616622
}
617623

618624
/**
@@ -1584,12 +1590,22 @@ public void setReportTypes(ReadableArray types) {
15841590
}
15851591

15861592
@ReactMethod
1587-
public void setBugReportingEnabled(boolean isEnabled) {
1588-
if (isEnabled) {
1589-
BugReporting.setState(Feature.State.ENABLED);
1590-
} else {
1591-
BugReporting.setState(Feature.State.DISABLED);
1592-
}
1593+
public void setBugReportingEnabled(final boolean isEnabled) {
1594+
new Handler(Looper.getMainLooper()).post(new Runnable() {
1595+
@Override
1596+
public void run() {
1597+
try {
1598+
if (isEnabled) {
1599+
BugReporting.setState(Feature.State.ENABLED);
1600+
} else {
1601+
BugReporting.setState(Feature.State.DISABLED);
1602+
}
1603+
} catch (Exception e) {
1604+
e.printStackTrace();
1605+
}
1606+
}
1607+
});
1608+
15931609
}
15941610

15951611
@ReactMethod
@@ -1607,12 +1623,21 @@ public void showBugReportingWithReportTypeAndOptions(String reportType, Readable
16071623
}
16081624

16091625
@ReactMethod
1610-
public void setChatsEnabled(boolean isEnabled) {
1611-
if (isEnabled) {
1612-
Chats.setState(Feature.State.ENABLED);
1613-
} else {
1614-
Chats.setState(Feature.State.DISABLED);
1615-
}
1626+
public void setChatsEnabled(final boolean isEnabled) {
1627+
new Handler(Looper.getMainLooper()).post(new Runnable() {
1628+
@Override
1629+
public void run() {
1630+
try {
1631+
if (isEnabled) {
1632+
Chats.setState(Feature.State.ENABLED);
1633+
} else {
1634+
Chats.setState(Feature.State.DISABLED);
1635+
}
1636+
} catch (Exception e) {
1637+
e.printStackTrace();
1638+
}
1639+
}
1640+
});
16161641
}
16171642

16181643
@ReactMethod
@@ -1621,12 +1646,21 @@ public void showChats() {
16211646
}
16221647

16231648
@ReactMethod
1624-
public void setRepliesEnabled(boolean isEnabled) {
1625-
if (isEnabled) {
1626-
Replies.setState(Feature.State.ENABLED);
1627-
} else {
1628-
Replies.setState(Feature.State.DISABLED);
1629-
}
1649+
public void setRepliesEnabled(final boolean isEnabled) {
1650+
new Handler(Looper.getMainLooper()).post(new Runnable() {
1651+
@Override
1652+
public void run() {
1653+
try {
1654+
if (isEnabled) {
1655+
Replies.setState(Feature.State.ENABLED);
1656+
} else {
1657+
Replies.setState(Feature.State.DISABLED);
1658+
}
1659+
} catch (Exception e) {
1660+
e.printStackTrace();
1661+
}
1662+
}
1663+
});
16301664
}
16311665

16321666
@ReactMethod
@@ -2099,4 +2133,4 @@ public Map<String, Object> getConstants() {
20992133

21002134
return constants;
21012135
}
2102-
}
2136+
}

0 commit comments

Comments
 (0)