Skip to content

Commit 1742c94

Browse files
alyezzAli Abdelfattah
andauthored
Fix - onReportSubmitHandler freeze on iOS (#489)
* Fix iOS freeze * undo indentation * refactor * adjust tests * update changelog Co-authored-by: Ali Abdelfattah <[email protected]>
1 parent b389a55 commit 1742c94

File tree

6 files changed

+18
-49
lines changed

6 files changed

+18
-49
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## master
2+
3+
* Fixes an issue with `onReportSubmitHandler` on iOS
4+
15
## v9.1.7 (2020-08-10)
26

37
* Fixes missing typescript definitions

__tests__/index.spec.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ describe('Instabug Module', () => {
6363
const hideView = sinon.spy(NativeModules.Instabug, 'hideView');
6464
const show = sinon.spy(NativeModules.Instabug, 'show');
6565
const setPreSendingHandler = sinon.spy(NativeModules.Instabug, 'setPreSendingHandler');
66-
const submitReport = sinon.spy(NativeModules.Instabug, 'submitReport');
6766
const callPrivateApi = sinon.spy(NativeModules.Instabug, 'callPrivateApi');
6867
const sendHandledJSCrash = sinon.spy(NativeModules.Instabug, 'sendHandledJSCrash');
6968
const sendJSCrash = sinon.spy(NativeModules.Instabug, 'sendJSCrash');
@@ -81,10 +80,9 @@ describe('Instabug Module', () => {
8180
isRunningLive.resetHistory();
8281
setFileAttachment.resetHistory();
8382
hideView.resetHistory();
84-
submitReport.resetHistory();
8583
setPreSendingHandler.resetHistory();
8684
IBGEventEmitter.removeAllListeners();
87-
85+
8886
});
8987

9088
it('componentDidAppearListener should call the native method reportScreenChange', () => {
@@ -583,9 +581,9 @@ describe('Instabug Module', () => {
583581
Instabug.onReportSubmitHandler(jest.fn());
584582
InstabugUtils.isOnReportHandlerSet.mockImplementation(() => true);
585583
const isReportHandlerSet = InstabugUtils.isOnReportHandlerSet();
586-
584+
587585
expect(isReportHandlerSet).toBe(true);
588-
586+
589587
});
590588

591589
it('should call the native method setPreSendingHandler with a function', () => {
@@ -619,7 +617,6 @@ describe('Instabug Module', () => {
619617
IBGEventEmitter.emit(IBGConstants.PRESENDING_HANDLER, report);
620618

621619
expect(IBGEventEmitter.getListeners(IBGConstants.PRESENDING_HANDLER).length).toEqual(1);
622-
expect(submitReport.calledOnce).toBe(true);
623620

624621
});
625622

@@ -634,7 +631,7 @@ describe('Instabug Module', () => {
634631
fileAttachments: ['path']
635632
};
636633
NativeModules.Instabug.getReport.mockResolvedValue(report);
637-
const jsonObject = {stack: 'error'};
634+
const jsonObject = { stack: 'error' };
638635
const callback = (rep) => {
639636
expect(rep).toBeInstanceOf(Report);
640637
expect(rep.tags).toBe(report.tags);
@@ -658,7 +655,7 @@ describe('Instabug Module', () => {
658655
Instabug.onReportSubmitHandler(jest.fn());
659656
IBGEventEmitter.emit(IBGConstants.SEND_HANDLED_CRASH, {});
660657
expect(IBGEventEmitter.getListeners(IBGConstants.SEND_HANDLED_CRASH).length).toEqual(0);
661-
658+
662659
});
663660

664661
it('should invoke callback on emitting the event IBGSendUnhandledJSCrash', async (done) => {
@@ -672,7 +669,7 @@ describe('Instabug Module', () => {
672669
fileAttachments: ['path']
673670
};
674671
NativeModules.Instabug.getReport.mockResolvedValue(report);
675-
const jsonObject = {stack: 'error'};
672+
const jsonObject = { stack: 'error' };
676673
const callback = (rep) => {
677674
expect(rep).toBeInstanceOf(Report);
678675
expect(rep.tags).toBe(report.tags);
@@ -696,7 +693,7 @@ describe('Instabug Module', () => {
696693
Instabug.onReportSubmitHandler(jest.fn());
697694
IBGEventEmitter.emit(IBGConstants.SEND_UNHANDLED_CRASH, {});
698695
expect(IBGEventEmitter.getListeners(IBGConstants.SEND_UNHANDLED_CRASH).length).toEqual(0);
699-
696+
700697
});
701698

702699
it('should invoke the native method callPrivateApi', () => {

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

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ public void setPreSendingHandler(final Callback preSendingHandler) {
13681368
MainThreadHandler.runOnMainThread(new Runnable() {
13691369
@Override
13701370
public void run() {
1371-
Report.OnReportCreatedListener listener = new Report.OnReportCreatedListener() {
1371+
Instabug.onReportSubmitHandler(new Report.OnReportCreatedListener() {
13721372
@Override
13731373
public void onReportCreated(Report report) {
13741374
WritableMap reportParam = Arguments.createMap();
@@ -1380,18 +1380,7 @@ public void onReportCreated(Report report) {
13801380
sendEvent(getReactApplicationContext(), "IBGpreSendingHandler", reportParam);
13811381
currentReport = report;
13821382
}
1383-
};
1384-
1385-
Method method = getMethod(Instabug.class, "onReportSubmitHandler_Private", Report.OnReportCreatedListener.class);
1386-
if (method != null) {
1387-
try {
1388-
method.invoke(null, listener);
1389-
} catch (IllegalAccessException e) {
1390-
e.printStackTrace();
1391-
} catch (InvocationTargetException e) {
1392-
e.printStackTrace();
1393-
}
1394-
}
1383+
});
13951384
}
13961385
});
13971386

@@ -1468,21 +1457,7 @@ public void addFileAttachmentWithDataToReport(String data, String fileName) {
14681457
}
14691458
}
14701459

1471-
@ReactMethod
1472-
public void submitReport() {
1473-
Method method = getMethod(Instabug.class, "setReport", Report.class);
1474-
if (method != null) {
1475-
try {
1476-
method.invoke(null, currentReport);
1477-
currentReport = null;
1478-
} catch (IllegalAccessException e) {
1479-
e.printStackTrace();
1480-
} catch (InvocationTargetException e) {
1481-
e.printStackTrace();
1482-
}
1483-
}
1484-
}
1485-
1460+
14861461
@ReactMethod
14871462
public void getReport(Promise promise) {
14881463
try {

index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,6 @@ const InstabugModule = {
751751
const { tags, consoleLogs, instabugLogs, userAttributes, fileAttachments } = report;
752752
const reportObj = new Report(tags, consoleLogs, instabugLogs, userAttributes, fileAttachments);
753753
preSendingHandler(reportObj);
754-
Instabug.submitReport();
755754

756755
});
757756

ios/RNInstabug/InstabugReactBridge.m

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,21 @@ - (dispatch_queue_t)methodQueue {
117117
}
118118
}
119119

120-
void (^globalReportCompletionHandler)(IBGReport *);
121120
IBGReport *currentReport = nil;
122121
RCT_EXPORT_METHOD(setPreSendingHandler:(RCTResponseSenderBlock)callBack) {
123122
if (callBack != nil) {
124-
[Instabug setWillSendReportHandler_private:^(IBGReport *report, void (^reportCompletionHandler)(IBGReport *)) {
123+
Instabug.willSendReportHandler = ^IBGReport * _Nonnull(IBGReport * _Nonnull report) {
125124
NSArray *tagsArray = report.tags;
126125
NSArray *instabugLogs= report.instabugLogs;
127126
NSArray *consoleLogs= report.consoleLogs;
128127
NSDictionary *userAttributes= report.userAttributes;
129128
NSArray *fileAttachments= report.fileLocations;
130129
NSDictionary *dict = @{ @"tagsArray" : tagsArray, @"instabugLogs" : instabugLogs, @"consoleLogs" : consoleLogs, @"userAttributes" : userAttributes, @"fileAttachments" : fileAttachments};
131130
[self sendEventWithName:@"IBGpreSendingHandler" body:dict];
131+
132132
currentReport = report;
133-
globalReportCompletionHandler = reportCompletionHandler;
134-
}];
133+
return report;
134+
};
135135
} else {
136136
Instabug.willSendReportHandler = nil;
137137
}
@@ -199,11 +199,6 @@ - (dispatch_queue_t)methodQueue {
199199
}
200200
}
201201

202-
RCT_EXPORT_METHOD(submitReport) {
203-
globalReportCompletionHandler(currentReport);
204-
currentReport = nil;
205-
}
206-
207202
RCT_EXPORT_METHOD(setSdkDebugLogsLevel:(IBGSDKDebugLogsLevel)sdkDebugLogsLevel) {
208203
[Instabug setSdkDebugLogsLevel:sdkDebugLogsLevel];
209204
}

jest/mockInstabug.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ jest.mock('NativeModules', () => {
4545
setPreSendingHandler: jest.fn(),
4646
callPrivateApi: jest.fn(),
4747
addListener: jest.fn(),
48-
submitReport: jest.fn(),
4948
getReport: jest.fn(),
5049
sendHandledJSCrash: jest.fn(),
5150
sendJSCrash: jest.fn(),

0 commit comments

Comments
 (0)