Skip to content

Commit 696adec

Browse files
committed
2 parents 42bef2e + 39610b5 commit 696adec

File tree

6 files changed

+611
-27
lines changed

6 files changed

+611
-27
lines changed

InstabugSample/index.android.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export default class InstabugSample extends Component {
2727
super(props);
2828
Instabug.startWithToken('0f0dc916bd9175e3b5d2fdf0cfa49a69',
2929
Instabug.invocationEvent.floatingButton);
30+
Instabug.setPreInvocationHandler(() => {
31+
Alert.alert("PreInvocationEvent", "Done :) ");
32+
});
3033
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
3134
this.state = {
3235
dataSource: ds.cloneWithRows(this._genRows({})),

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

Lines changed: 286 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
import com.instabug.library.logging.InstabugLog;
2323
import com.instabug.library.bugreporting.model.ReportCategory;
2424
import com.instabug.library.InstabugCustomTextPlaceHolder;
25+
import com.instabug.library.user.UserEventParam;
26+
import com.instabug.library.OnSdkDismissedCallback;
27+
import com.instabug.library.bugreporting.model.Bug;
28+
import com.instabug.survey.InstabugSurvey;
29+
30+
import com.instabug.reactlibrary.utils.ArrayUtil;
31+
import com.instabug.reactlibrary.utils.MapUtil;
2532

2633
import java.util.ArrayList;
2734
import java.util.HashMap;
@@ -353,17 +360,18 @@ public void IBGLog(String message) {
353360
*/
354361
@ReactMethod
355362
public void getTags(Callback tagsCallback) {
356-
private WritableArray tagsArray;
363+
WritableArray tagsArray;
357364
try {
358365
ArrayList<String> tags = mInstabug.getTags();
359366
tagsArray = new WritableNativeArray();
360367
for (int i = 0; i < tags.size(); i++) {
361368
tagsArray.pushString(tags.get(i));
362369
}
370+
tagsCallback.invoke(tagsArray);
371+
363372
} catch (Exception e) {
364373
e.printStackTrace();
365374
}
366-
tagsCallback.invoke(tagsArray);
367375
}
368376

369377
/**
@@ -651,10 +659,10 @@ public void getUserAttribute(String key, Callback userAttributeCallback) {
651659
String userAttribute;
652660
try {
653661
userAttribute = mInstabug.getUserAttribute(key);
662+
userAttributeCallback.invoke(userAttribute);
654663
} catch (Exception e) {
655664
e.printStackTrace();
656665
}
657-
userAttributeCallback.invoke(userAttribute);
658666
}
659667

660668
/**
@@ -797,6 +805,281 @@ public void setStringToKey(String string, String key) {
797805
}
798806
}
799807

808+
/**
809+
* Sets the default value of the user's email to null and show email field and remove user
810+
* name from all reports
811+
* It also reset the chats on device and removes user attributes, user data and completed
812+
* surveys.
813+
*/
814+
@ReactMethod
815+
public void logOut() {
816+
try {
817+
mInstabug.logoutUser();
818+
} catch (java.lang.Exception exception) {
819+
exception.printStackTrace();
820+
}
821+
}
822+
823+
/**
824+
* Enables/disables screenshot view when reporting a bug/improvement.
825+
* By default, screenshot view is shown when reporting a bug, but not when
826+
* sending feedback.
827+
*
828+
* @param {boolean} willSkipScreenshotAnnotation sets whether screenshot view is
829+
* shown or not. Passing YES will show screenshot view for both feedback and
830+
* bug reporting, while passing NO will disable it for both.
831+
*/
832+
@ReactMethod
833+
public void setWillSkipScreenshotAnnotation(boolean willSkipScreenshotAnnotation) {
834+
try {
835+
mInstabug.setWillSkipScreenshotAnnotation(willSkipScreenshotAnnotation);
836+
} catch (java.lang.Exception exception) {
837+
exception.printStackTrace();
838+
}
839+
}
840+
841+
/**
842+
* Logs a user event that happens through the lifecycle of the application.
843+
* Logged user events are going to be sent with each report, as well as at the end of a session.
844+
*
845+
* @param {string} name Event name.
846+
*/
847+
@ReactMethod
848+
public void logUserEventWithName(String name) {
849+
try {
850+
mInstabug.logUserEvent(name);
851+
} catch (java.lang.Exception exception) {
852+
exception.printStackTrace();
853+
}
854+
}
855+
856+
/**
857+
* Logs a user event that happens through the lifecycle of the application.
858+
* Logged user events are going to be sent with each report, as well as at the end of a
859+
* session.
860+
*
861+
* @param {string} name Event name.
862+
* @param {ReadableMap} params An optional ReadableMap to be associated with the event.
863+
*/
864+
@ReactMethod
865+
public void logUserEventWithNameAndParams(String name, ReadableMap params) {
866+
try {
867+
Map<String, Object> paramsMap = MapUtil.toMap(params);
868+
UserEventParam[] userEventParams = new UserEventParam[paramsMap.size()];
869+
int index = 0;
870+
UserEventParam userEventParam;
871+
for (Map.Entry<String, Object> entry : paramsMap.entrySet()) {
872+
userEventParam = new UserEventParam().setKey(entry.getKey())
873+
.setValue((entry.getValue()).toString());
874+
userEventParams[index] = userEventParam;
875+
index++;
876+
}
877+
878+
mInstabug.logUserEvent(name, userEventParams);
879+
} catch (java.lang.Exception exception) {
880+
exception.printStackTrace();
881+
}
882+
}
883+
884+
/**
885+
* Sets a block of code to be executed just before the SDK's UI is presented.
886+
* This block is executed on the UI thread. Could be used for performing any
887+
* UI changes before the SDK's UI is shown.
888+
*
889+
* @param {preInvocationHandler} preInvocationHandler - A callback that gets executed before
890+
* invoking the SDK
891+
*/
892+
@ReactMethod
893+
public void setPreInvocationHandler(final Callback preInvocationHandler) {
894+
try {
895+
Runnable preInvocationRunnable = new Runnable() {
896+
@Override
897+
public void run() {
898+
preInvocationHandler.invoke();
899+
}
900+
};
901+
mInstabug.setPreInvocation(preInvocationRunnable);
902+
} catch (java.lang.Exception exception) {
903+
exception.printStackTrace();
904+
}
905+
}
906+
907+
/**
908+
* Sets a block of code to be executed before sending each report.
909+
* This block is executed in the background before sending each report. Could
910+
* be used for attaching logs and extra data to reports.
911+
*
912+
* @param {preSendingHandler} preSendingHandler - A callback that gets executed before
913+
* sending each bug
914+
* report.
915+
*/
916+
@ReactMethod
917+
public void setPreSendingHandler(final Callback preSendingHandler) {
918+
try {
919+
Runnable preSendingRunnable = new Runnable() {
920+
@Override
921+
public void run() {
922+
preSendingHandler.invoke();
923+
}
924+
};
925+
mInstabug.setPreSendingRunnable(preSendingRunnable);
926+
} catch (java.lang.Exception exception) {
927+
exception.printStackTrace();
928+
}
929+
}
930+
931+
/**
932+
* Sets a block of code to be executed right after the SDK's UI is dismissed.
933+
* This block is executed on the UI thread. Could be used for performing any
934+
* UI changes after the SDK's UI is dismissed.
935+
*
936+
* @param {postInvocationHandler} postInvocationHandler - A callback to get executed after
937+
* dismissing the SDK.
938+
*/
939+
@ReactMethod
940+
public void setPostInvocationHandler(final Callback postInvocationHandler) {
941+
try {
942+
943+
mInstabug.setOnSdkDismissedCallback(new OnSdkDismissedCallback() {
944+
@Override
945+
public void onSdkDismissed(DismissType issueState, Bug.Type bugType) {
946+
postInvocationHandler.invoke();
947+
}
948+
});
949+
950+
} catch (java.lang.Exception exception) {
951+
exception.printStackTrace();
952+
}
953+
}
954+
955+
/**
956+
* Show any valid survey if exist
957+
*
958+
* @return return true if a valid survey was shown otherwise false
959+
*/
960+
@ReactMethod
961+
public void showSurveysIfAvailable() {
962+
try {
963+
mInstabug.showValidSurvey();
964+
} catch (java.lang.Exception exception) {
965+
exception.printStackTrace();
966+
}
967+
}
968+
969+
/**
970+
* Show any valid survey if exist
971+
*
972+
* @return return true if a valid survey was shown otherwise false
973+
*/
974+
@ReactMethod
975+
public void setSurveysEnabled(boolean surveysEnabled) {
976+
try {
977+
InstabugSurvey.setSurveysAutoShowing(surveysEnabled);
978+
} catch (java.lang.Exception exception) {
979+
exception.printStackTrace();
980+
}
981+
}
982+
983+
984+
/**
985+
* Sets the runnable that gets executed just before showing any valid survey<br/>
986+
* WARNING: This runs on your application's main UI thread. Please do not include
987+
* any blocking operations to avoid ANRs.
988+
*
989+
* @param preShowingSurveyRunnable to run on the UI thread before showing any valid survey
990+
*/
991+
@ReactMethod
992+
public void setWillShowSurveyHandler(final Callback willShowSurveyHandler) {
993+
try {
994+
Runnable willShowSurveyRunnable = new Runnable() {
995+
@Override
996+
public void run() {
997+
willShowSurveyHandler.invoke();
998+
}
999+
};
1000+
mInstabug.setPreShowingSurveyRunnable(willShowSurveyRunnable);
1001+
} catch (java.lang.Exception exception) {
1002+
exception.printStackTrace();
1003+
}
1004+
}
1005+
1006+
/**
1007+
* Sets the runnable that gets executed just after showing any valid survey<br/>
1008+
* WARNING: This runs on your application's main UI thread. Please do not include
1009+
* any blocking operations to avoid ANRs.
1010+
*
1011+
* @param afterShowingSurveyRunnable to run on the UI thread after showing any valid survey
1012+
*/
1013+
@ReactMethod
1014+
public void setDidDismissSurveyHandler(final Callback didDismissSurveyHandler) {
1015+
try {
1016+
Runnable didDismissSurveyRunnable = new Runnable() {
1017+
@Override
1018+
public void run() {
1019+
didDismissSurveyHandler.invoke();
1020+
}
1021+
};
1022+
mInstabug.setAfterShowingSurveyRunnable(didDismissSurveyRunnable);
1023+
} catch (java.lang.Exception exception) {
1024+
exception.printStackTrace();
1025+
}
1026+
}
1027+
1028+
/**
1029+
* Enable/Disable prompt options when SDK invoked. When only a single option is enabled it
1030+
* becomes the default
1031+
* invocation option that SDK gets invoked with and prompt options screen will not show. When
1032+
* none is enabled, Bug
1033+
* reporting becomes the default invocation option.
1034+
*
1035+
* @param {boolean} chat weather Talk to us is enable or not
1036+
* @param {boolean} bug weather Report a Problem is enable or not
1037+
* @param {boolean} feedback weather General Feedback is enable or not
1038+
*/
1039+
@ReactMethod
1040+
public void setPromptOptionsEnabled(boolean chat, boolean bug, boolean feedback) {
1041+
try {
1042+
mInstabug.setPromptOptionsEnabled(chat, bug, feedback);
1043+
} catch (Exception e) {
1044+
e.printStackTrace();
1045+
}
1046+
}
1047+
1048+
/**
1049+
* Clears all Uris of the attached files.
1050+
* The URIs which added via {@link Instabug#addFileAttachment} API not the physical files.
1051+
*/
1052+
@ReactMethod
1053+
public void clearFileAttachment() {
1054+
try {
1055+
mInstabug.clearFileAttachment();
1056+
} catch (Exception e) {
1057+
e.printStackTrace();
1058+
}
1059+
}
1060+
1061+
1062+
/**
1063+
* Sets a block of code that gets executed when a new message is received.
1064+
*
1065+
* @param {onNewMessgaeHandler} onNewMessageHandler - A callback that gets
1066+
* executed when a new message is received.
1067+
*/
1068+
@ReactMethod
1069+
public void setOnNewMessageHandler(final Callback onNewMessageHandler) {
1070+
try {
1071+
Runnable onNewMessageRunnable = new Runnable() {
1072+
@Override
1073+
public void run() {
1074+
onNewMessageHandler.invoke();
1075+
}
1076+
};
1077+
mInstabug.setNewMessageHandler(onNewMessageRunnable);
1078+
} catch (java.lang.Exception exception) {
1079+
exception.printStackTrace();
1080+
}
1081+
}
1082+
8001083
private InstabugCustomTextPlaceHolder.Key getStringToKeyConstant(String key) {
8011084
String keyInLowerCase = key.toLowerCase();
8021085
switch (keyInLowerCase) {

0 commit comments

Comments
 (0)