7
7
import android .util .Log ;
8
8
9
9
import com .facebook .react .bridge .Arguments ;
10
+ import com .facebook .react .bridge .Promise ;
10
11
import com .facebook .react .bridge .ReactApplicationContext ;
11
12
import com .facebook .react .bridge .ReactContextBaseJavaModule ;
12
13
import com .facebook .react .bridge .ReactMethod ;
51
52
import com .instabug .library .visualusersteps .State ;
52
53
53
54
import com .instabug .reactlibrary .utils .ArrayUtil ;
55
+ import com .instabug .reactlibrary .utils .ReportUtil ;
54
56
import com .instabug .reactlibrary .utils .InstabugUtil ;
55
57
import com .instabug .reactlibrary .utils .MapUtil ;
56
58
import com .instabug .survey .OnDismissCallback ;
@@ -212,6 +214,7 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
212
214
private Instabug mInstabug ;
213
215
private InstabugInvocationEvent invocationEvent ;
214
216
private InstabugCustomTextPlaceHolder placeHolders ;
217
+ private Report currentReport ;
215
218
216
219
/**
217
220
* Instantiates a new Rn instabug reactnative module.
@@ -452,7 +455,8 @@ public void setFileAttachment(String fileUri, String fileNameWithExtension) {
452
455
@ ReactMethod
453
456
public void sendJSCrash (String exceptionObject ) {
454
457
try {
455
- sendJSCrashByReflection (exceptionObject , false );
458
+ JSONObject jsonObject = new JSONObject (exceptionObject );
459
+ sendJSCrashByReflection (jsonObject , false , null );
456
460
} catch (Exception e ) {
457
461
e .printStackTrace ();
458
462
}
@@ -466,7 +470,8 @@ public void sendJSCrash(String exceptionObject) {
466
470
@ ReactMethod
467
471
public void sendHandledJSCrash (String exceptionObject ) {
468
472
try {
469
- sendJSCrashByReflection (exceptionObject , true );
473
+ JSONObject jsonObject = new JSONObject (exceptionObject );
474
+ sendJSCrashByReflection (jsonObject , true , null );
470
475
} catch (Exception e ) {
471
476
e .printStackTrace ();
472
477
}
@@ -490,23 +495,20 @@ public void setCrashReportingEnabled(boolean isEnabled) {
490
495
}
491
496
}
492
497
493
- private void sendJSCrashByReflection (String exceptionObject , boolean isHandled ) {
498
+ private void sendJSCrashByReflection (JSONObject exceptionObject , boolean isHandled , Report report ) {
494
499
try {
495
- JSONObject newJSONObject = new JSONObject (exceptionObject );
496
- Method method = getMethod (Class .forName ("com.instabug.crash.CrashReporting" ), "reportException" , JSONObject .class , boolean .class );
500
+ Method method = getMethod (Class .forName ("com.instabug.crash.CrashReporting" ), "reportException" , JSONObject .class , boolean .class , Report .class );
497
501
if (method != null ) {
498
- method .invoke (null , newJSONObject , isHandled );
502
+ method .invoke (null , exceptionObject , isHandled , currentReport );
503
+ currentReport = null ;
499
504
}
500
505
} catch (ClassNotFoundException e ) {
501
506
e .printStackTrace ();
502
- } catch (InvocationTargetException e ) {
503
- e .printStackTrace ();
504
507
} catch (IllegalAccessException e ) {
505
508
e .printStackTrace ();
506
- } catch (JSONException e ) {
509
+ } catch (InvocationTargetException e ) {
507
510
e .printStackTrace ();
508
511
}
509
-
510
512
}
511
513
512
514
/**
@@ -1185,25 +1187,144 @@ public void onInvoke() {
1185
1187
*/
1186
1188
@ ReactMethod
1187
1189
public void setPreSendingHandler (final Callback preSendingHandler ) {
1190
+ Report .OnReportCreatedListener listener = new Report .OnReportCreatedListener () {
1191
+ @ Override
1192
+ public void onReportCreated (Report report ) {
1193
+ WritableMap reportParam = Arguments .createMap ();
1194
+ reportParam .putArray ("tagsArray" , convertArrayListToWritableArray (report .getTags ()));
1195
+ reportParam .putArray ("consoleLogs" , convertArrayListToWritableArray (report .getConsoleLog ()));
1196
+ reportParam .putString ("userData" , report .getUserData ());
1197
+ reportParam .putMap ("userAttributes" , convertFromHashMapToWriteableMap (report .getUserAttributes ()));
1198
+ reportParam .putMap ("fileAttachments" , convertFromHashMapToWriteableMap (report .getFileAttachments ()));
1199
+ sendEvent (getReactApplicationContext (), "IBGpreSendingHandler" , reportParam );
1200
+ currentReport = report ;
1201
+ }
1202
+ };
1203
+
1204
+ Method method = getMethod (Instabug .class , "onReportSubmitHandler_Private" , Report .OnReportCreatedListener .class );
1205
+ if (method != null ) {
1206
+ try {
1207
+ method .invoke (null , listener );
1208
+ } catch (IllegalAccessException e ) {
1209
+ e .printStackTrace ();
1210
+ } catch (InvocationTargetException e ) {
1211
+ e .printStackTrace ();
1212
+ }
1213
+ }
1214
+ }
1215
+
1216
+ @ ReactMethod
1217
+ public void appendTagToReport (String tag ) {
1218
+ if (currentReport != null ) {
1219
+ currentReport .addTag (tag );
1220
+ }
1221
+ }
1222
+
1223
+ @ ReactMethod
1224
+ public void appendConsoleLogToReport (String consoleLog ) {
1225
+ if (currentReport != null ) {
1226
+ currentReport .appendToConsoleLogs (consoleLog );
1227
+ }
1228
+ }
1229
+
1230
+ @ ReactMethod
1231
+ public void setUserAttributeToReport (String key , String value ) {
1232
+ if (currentReport != null ) {
1233
+ currentReport .setUserAttribute (key , value );
1234
+ }
1235
+ }
1236
+
1237
+ @ ReactMethod
1238
+ public void logDebugToReport (String log ) {
1239
+ if (currentReport != null ) {
1240
+ currentReport .logDebug (log );
1241
+ }
1242
+ }
1243
+
1244
+ @ ReactMethod
1245
+ public void logVerboseToReport (String log ) {
1246
+ if (currentReport != null ) {
1247
+ currentReport .logVerbose (log );
1248
+ }
1249
+ }
1250
+
1251
+ @ ReactMethod
1252
+ public void logWarnToReport (String log ) {
1253
+ if (currentReport != null ) {
1254
+ currentReport .logWarn (log );
1255
+ }
1256
+ }
1257
+
1258
+ @ ReactMethod
1259
+ public void logErrorToReport (String log ) {
1260
+ if (currentReport != null ) {
1261
+ currentReport .logError (log );
1262
+ }
1263
+ }
1264
+
1265
+ @ ReactMethod
1266
+ public void logInfoToReport (String log ) {
1267
+ if (currentReport != null ) {
1268
+ currentReport .logInfo (log );
1269
+ }
1270
+ }
1271
+
1272
+ @ ReactMethod
1273
+ public void addFileAttachmentWithURLToReport (String urlString , String fileName ) {
1274
+ if (currentReport != null ) {
1275
+ Uri uri = Uri .parse (urlString );
1276
+ currentReport .addFileAttachment (uri , fileName );
1277
+ }
1278
+ }
1279
+
1280
+ @ ReactMethod
1281
+ public void addFileAttachmentWithDataToReport (String data , String fileName ) {
1282
+ if (currentReport != null ) {
1283
+ currentReport .addFileAttachment (data .getBytes (), fileName );
1284
+ }
1285
+ }
1286
+
1287
+ @ ReactMethod
1288
+ public void submitReport () {
1289
+ Method method = getMethod (Instabug .class , "setReport" , Report .class );
1290
+ if (method != null ) {
1291
+ try {
1292
+ method .invoke (null , currentReport );
1293
+ currentReport = null ;
1294
+ } catch (IllegalAccessException e ) {
1295
+ e .printStackTrace ();
1296
+ } catch (InvocationTargetException e ) {
1297
+ e .printStackTrace ();
1298
+ }
1299
+ }
1300
+ }
1301
+
1302
+ @ ReactMethod
1303
+ public void getReport (Promise promise ) {
1188
1304
try {
1305
+ Method method = getMethod (Class .forName ("com.instabug.library.Instabug" ), "getReport" );
1306
+ if (method != null ) {
1307
+ Report report = (Report ) method .invoke (null );
1308
+ WritableMap reportParam = Arguments .createMap ();
1309
+ reportParam .putArray ("tagsArray" , convertArrayListToWritableArray (report .getTags ()));
1310
+ reportParam .putArray ("consoleLogs" , ReportUtil .parseConsoleLogs (report .getConsoleLog ()));
1311
+ reportParam .putString ("userData" , report .getUserData ());
1312
+ reportParam .putMap ("userAttributes" , convertFromHashMapToWriteableMap (report .getUserAttributes ()));
1313
+ reportParam .putMap ("fileAttachments" , convertFromHashMapToWriteableMap (report .getFileAttachments ()));
1314
+ promise .resolve (reportParam );
1315
+ currentReport = report ;
1316
+ }
1189
1317
1190
- Instabug .onReportSubmitHandler (new Report .OnReportCreatedListener () {
1191
- @ Override
1192
- public void onReportCreated (Report report ) {
1193
- WritableMap reportParam = Arguments .createMap ();
1194
- reportParam .putArray ("tagsArray" , convertArrayListToWritableArray (report .getTags ()));
1195
- reportParam .putArray ("consoleLogs" , convertArrayListToWritableArray (report .getConsoleLog ()));
1196
- reportParam .putString ("userData" , report .getUserData ());
1197
- reportParam .putMap ("userAttributes" , convertFromHashMapToWriteableMap (report .getUserAttributes ()));
1198
- reportParam .putMap ("fileAttachments" , convertFromHashMapToWriteableMap (report .getFileAttachments ()));
1199
- sendEvent (getReactApplicationContext (), "IBGpreSendingHandler" , reportParam );
1200
- }
1201
- });
1202
- } catch (java .lang .Exception exception ) {
1203
- exception .printStackTrace ();
1318
+ } catch (ClassNotFoundException e ) {
1319
+ promise .reject (e );
1320
+ } catch (IllegalAccessException e ) {
1321
+ promise .reject (e );
1322
+ } catch (InvocationTargetException e ) {
1323
+ promise .reject (e );
1204
1324
}
1205
1325
}
1206
1326
1327
+
1207
1328
private WritableMap convertFromHashMapToWriteableMap (HashMap hashMap ) {
1208
1329
WritableMap writableMap = new WritableNativeMap ();
1209
1330
for (int i = 0 ; i < hashMap .size (); i ++) {
0 commit comments