Skip to content

Commit c56f5fb

Browse files
Enable InstabugSurvey APIs for android
1 parent 2545f7f commit c56f5fb

File tree

2 files changed

+80
-4
lines changed

2 files changed

+80
-4
lines changed

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.instabug.library.user.UserEventParam;
2626
import com.instabug.library.OnSdkDismissedCallback;
2727
import com.instabug.library.bugreporting.model.Bug;
28+
import com.instabug.library.temp.InstabugSurvey;
2829

2930
import com.instabug.reactlibrary.utils.ArrayUtil;
3031
import com.instabug.reactlibrary.utils.MapUtil;
@@ -951,6 +952,79 @@ public void onSdkDismissed(DismissType issueState, Bug.Type bugType) {
951952
}
952953
}
953954

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+
9541028
private InstabugCustomTextPlaceHolder.Key getStringToKeyConstant(String key) {
9551029
String keyInLowerCase = key.toLowerCase();
9561030
switch (keyInLowerCase) {

index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,10 @@ module.exports = {
656656
'IBGWillShowSurvey',
657657
willShowSurveyHandler
658658
);
659-
660-
Instabug.setWillShowSurveyHandler(willShowSurveyHandler);
661659
}
660+
661+
Instabug.setWillShowSurveyHandler(willShowSurveyHandler);
662+
662663
},
663664

664665
setDidDismissSurveyHandler: function (didDismissSurveyHandler) {
@@ -668,9 +669,10 @@ module.exports = {
668669
'IBGDidDismissSurvey',
669670
didDismissSurveyHandler
670671
);
671-
672-
Instabug.setDidDismissSurveyHandler(didDismissSurveyHandler);
673672
}
673+
674+
Instabug.setDidDismissSurveyHandler(didDismissSurveyHandler);
675+
674676
},
675677

676678
/**

0 commit comments

Comments
 (0)