diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a944012a..2dc7ebd30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v8.5.4 (2019-08-10) + +* Hot Fixes an issue with `Instabug.setFloatingButtonEdge` and `Instabug.setEnabledAttachmentTypes` causing the app to crash. + ## v8.5.3 (2019-08-08) * Fixes hang/crash issues on iOS 9 devices diff --git a/__tests__/bugReporting.spec.js b/__tests__/bugReporting.spec.js index de8953753..e29655d00 100644 --- a/__tests__/bugReporting.spec.js +++ b/__tests__/bugReporting.spec.js @@ -33,6 +33,9 @@ describe('Testing BugReporting Module', () => { const setAutoScreenRecordingMaxDuration = sinon.spy(NativeModules.IBGBugReporting, 'setAutoScreenRecordingMaxDuration'); const setViewHierarchyEnabled = sinon.spy(NativeModules.IBGBugReporting, 'setViewHierarchyEnabled'); const didSelectPromptOptionHandler = sinon.spy(NativeModules.IBGBugReporting, 'setDidSelectPromptOptionHandler'); + const setFloatingButtonEdge = sinon.spy(NativeModules.IBGBugReporting, 'setFloatingButtonEdge'); + const setEnabledAttachmentTypes = sinon.spy(NativeModules.IBGBugReporting, 'setEnabledAttachmentTypes'); + beforeEach(() => { setShakingThresholdForiPhone.resetHistory(); @@ -258,4 +261,22 @@ describe('Testing BugReporting Module', () => { }); + it('should call the native method setFloatingButtonEdge', () => { + + const offsetFromTop = 10; + const edge = Instabug.floatingButtonEdge.left; + BugReporting.setFloatingButtonEdge(edge, offsetFromTop); + + expect(setFloatingButtonEdge.calledOnceWithExactly(edge, offsetFromTop)).toBe(true); + + }); + + it('should call the native method setEnabledAttachmentTypes', () => { + + BugReporting.setEnabledAttachmentTypes(true, true, false, true); + + expect(setEnabledAttachmentTypes.calledOnceWithExactly(true, true, false, true)).toBe(true); + + }); + }); diff --git a/__tests__/index.spec.js b/__tests__/index.spec.js index 964738be8..7ce55b6df 100644 --- a/__tests__/index.spec.js +++ b/__tests__/index.spec.js @@ -25,7 +25,7 @@ describe('Instabug Module', () => { const setIBGLogPrintsToConsole = sinon.spy(NativeModules.Instabug, 'setIBGLogPrintsToConsole'); const setSessionProfilerEnabled = sinon.spy(NativeModules.Instabug, 'setSessionProfilerEnabled'); const setPushNotificationsEnabled = sinon.spy(NativeModules.Instabug, 'setPushNotificationsEnabled'); - const setFloatingButtonEdge = sinon.spy(NativeModules.Instabug, 'setFloatingButtonEdge'); + const setFloatingButtonEdge = sinon.spy(NativeModules.IBGBugReporting, 'setFloatingButtonEdge'); const setLocale = sinon.spy(NativeModules.Instabug, 'setLocale'); const setColorTheme = sinon.spy(NativeModules.Instabug, 'setColorTheme'); const setPrimaryColor = sinon.spy(NativeModules.Instabug, 'setPrimaryColor'); @@ -33,7 +33,7 @@ describe('Instabug Module', () => { const resetTags = sinon.spy(NativeModules.Instabug, 'resetTags'); const getTags = sinon.spy(NativeModules.Instabug, 'getTags'); const setString = sinon.spy(NativeModules.Instabug, 'setString'); - const setEnabledAttachmentTypes = sinon.spy(NativeModules.Instabug, 'setEnabledAttachmentTypes'); + const setEnabledAttachmentTypes = sinon.spy(NativeModules.IBGBugReporting, 'setEnabledAttachmentTypes'); const identifyUserWithEmail = sinon.spy(NativeModules.Instabug, 'identifyUserWithEmail'); const logOut = sinon.spy(NativeModules.Instabug, 'logOut'); const logUserEventWithName = sinon.spy(NativeModules.Instabug, 'logUserEventWithName'); @@ -71,7 +71,6 @@ describe('Instabug Module', () => { setTrackUserSteps.resetHistory(); setIBGLogPrintsToConsole.resetHistory(); setPushNotificationsEnabled.resetHistory(); - setFloatingButtonEdge.resetHistory(); log.resetHistory(); setDebugEnabled.resetHistory(); enable.resetHistory(); @@ -169,18 +168,8 @@ describe('Instabug Module', () => { }); - it('should not call the native method setPushNotificationsEnabled when platform is android', () => { - - Platform.OS = 'android'; - Instabug.setPushNotificationsEnabled(true); - - expect(setPushNotificationsEnabled.notCalled).toBe(true); - - }); - it('should call the native method setFloatingButtonEdge', () => { - Platform.OS = 'ios'; const offsetFromTop = 10; const edge = Instabug.floatingButtonEdge.left; Instabug.setFloatingButtonEdge(edge, offsetFromTop); @@ -189,12 +178,12 @@ describe('Instabug Module', () => { }); - it('should not call the native method setFloatingButtonEdge when platform is android', () => { + it('should not call the native method setPushNotificationsEnabled when platform is android', () => { Platform.OS = 'android'; - Instabug.setPushNotificationsEnabled(Instabug.floatingButtonEdge.left, 10); + Instabug.setPushNotificationsEnabled(true); - expect(setFloatingButtonEdge.notCalled).toBe(true); + expect(setPushNotificationsEnabled.notCalled).toBe(true); }); diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java index 8a792090b..0e68d954e 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java @@ -544,25 +544,6 @@ public void run() { } }); } - - /** - * Sets whether attachments in bug reporting and in-app messaging are enabled or not. - * - * @param screenshot A boolean to enable or disable screenshot attachments. - * @param {boolean} extraScreenShot A boolean to enable or disable extra screenshot attachments. - * @param {boolean} galleryImage A boolean to enable or disable gallery image attachments. - * @param {boolean} screenRecording A boolean to enable or disable screen recording attachments. - */ - @ReactMethod - public void setEnabledAttachmentTypes(boolean screenshot, boolean extraScreenshot, boolean - galleryImage, boolean screenRecording) { - try { - BugReporting.setAttachmentTypesEnabled(screenshot, extraScreenshot, galleryImage, - screenRecording); - } catch (Exception e) { - e.printStackTrace(); - } - } /** * Gets tags. @@ -2079,22 +2060,6 @@ public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) { }); } - - @ReactMethod - public void setFloatingButtonEdge(final String floatingButtonEdge, final int floatingButtonOffset) { - new Handler(Looper.getMainLooper()).post(new Runnable() { - @Override - public void run() { - BugReporting.setFloatingButtonOffset(floatingButtonOffset); - if (floatingButtonEdge.equals("left")) - BugReporting.setFloatingButtonEdge(InstabugFloatingButtonEdge.LEFT); - else - BugReporting.setFloatingButtonEdge(InstabugFloatingButtonEdge.RIGHT); - } - }); - } - - private InstabugCustomTextPlaceHolder.Key getStringToKeyConstant(String key) { switch (key) { case SHAKE_HINT: diff --git a/index.js b/index.js index 4851db68a..5fd7d662f 100644 --- a/index.js +++ b/index.js @@ -189,6 +189,7 @@ const InstabugModule = { }, /** + * @deprecated use {@link BugReporting.setFloatingButtonEdge} * Sets the default edge and offset from the top at which the floating button * will be shown. Different orientations are already handled. * Default for `floatingButtonEdge` is `rectEdge.maxX`. @@ -199,7 +200,7 @@ const InstabugModule = { * floating button. */ setFloatingButtonEdge(floatingButtonEdge, offsetFromTop) { - Instabug.setFloatingButtonEdge(floatingButtonEdge, offsetFromTop); + BugReporting.setFloatingButtonEdge(floatingButtonEdge, offsetFromTop); }, /** @@ -279,6 +280,7 @@ const InstabugModule = { }, /** + * @deprecated use {@link BugReporting.setEnabledAttachmentTypes} * Sets whether attachments in bug reporting and in-app messaging are enabled or not. * @param {boolean} screenshot A boolean to enable or disable screenshot attachments. * @param {boolean} extraScreenshot A boolean to enable or disable extra @@ -294,7 +296,7 @@ const InstabugModule = { galleryImage, screenRecording ) { - Instabug.setEnabledAttachmentTypes( + BugReporting.setEnabledAttachmentTypes( screenshot, extraScreenshot, galleryImage, diff --git a/ios/RNInstabug/InstabugBugReportingBridge.h b/ios/RNInstabug/InstabugBugReportingBridge.h index b36bf91f1..feba6cf16 100644 --- a/ios/RNInstabug/InstabugBugReportingBridge.h +++ b/ios/RNInstabug/InstabugBugReportingBridge.h @@ -27,6 +27,8 @@ - (void)setOptions:(NSArray *)optionsArray; +- (void)setFloatingButtonEdge:(CGRectEdge)floatingButtonEdge withTopOffset:(double)floatingButtonOffsetFromTop; + - (void)invokeWithInvocationModeAndOptions:(IBGInvocationMode)invocationMode options:(NSArray *)options; - (void)setOnInvokeHandler:(RCTResponseSenderBlock)callBack; diff --git a/jest/mockBugReporting.js b/jest/mockBugReporting.js index 2be5e8a28..bbd9b57e5 100644 --- a/jest/mockBugReporting.js +++ b/jest/mockBugReporting.js @@ -4,6 +4,7 @@ jest.mock('NativeModules', () => { setEnabled: jest.fn(), setInvocationEvents: jest.fn(), setOptions: jest.fn(), + setFloatingButtonEdge: jest.fn(), setShakingThresholdForiPhone: jest.fn(), setShakingThresholdForiPad: jest.fn(), setShakingThresholdForAndroid: jest.fn(), @@ -16,6 +17,7 @@ jest.mock('NativeModules', () => { setAutoScreenRecordingEnabled: jest.fn(), setAutoScreenRecordingMaxDuration: jest.fn(), setViewHierarchyEnabled: jest.fn(), + setEnabledAttachmentTypes: jest.fn(), setDidSelectPromptOptionHandler: jest.fn() }, Instabug: {} diff --git a/jest/mockInstabug.js b/jest/mockInstabug.js index 0b1c5f18d..76d08bc37 100644 --- a/jest/mockInstabug.js +++ b/jest/mockInstabug.js @@ -8,7 +8,6 @@ jest.mock('NativeModules', () => { didSelectPromptOptionHandler: jest.fn(), setSessionProfilerEnabled: jest.fn(), setPushNotificationsEnabled: jest.fn(), - setFloatingButtonEdge: jest.fn(), setLocale: jest.fn(), setColorTheme: jest.fn(), setPrimaryColor: jest.fn(), @@ -16,7 +15,6 @@ jest.mock('NativeModules', () => { resetTags: jest.fn(), getTags: jest.fn(cb => cb(['tags1', 'tags2'])), setString: jest.fn(), - setEnabledAttachmentTypes: jest.fn(), identifyUserWithEmail: jest.fn(), logOut: jest.fn(), logUserEventWithName: jest.fn(), @@ -52,5 +50,9 @@ jest.mock('NativeModules', () => { sendJSCrash: jest.fn() }, + IBGBugReporting: { + setFloatingButtonEdge: jest.fn(), + setEnabledAttachmentTypes: jest.fn(), + } }; }); \ No newline at end of file diff --git a/modules/BugReporting.js b/modules/BugReporting.js index c25eb7ed8..38704392f 100644 --- a/modules/BugReporting.js +++ b/modules/BugReporting.js @@ -256,6 +256,44 @@ export default { IBGBugReporting.setDidSelectPromptOptionHandler(didSelectPromptOptionHandler); }, + /** + * Sets the default edge and offset from the top at which the floating button + * will be shown. Different orientations are already handled. + * Default for `floatingButtonEdge` is `rectEdge.maxX`. + * Default for `floatingButtonOffsetFromTop` is 50 + * @param {rectEdge} floatingButtonEdge `maxX` to show on the right, + * or `minX` to show on the left. + * @param {number} offsetFromTop floatingButtonOffsetFromTop Top offset for + * floating button. + */ + setFloatingButtonEdge(floatingButtonEdge, offsetFromTop) { + IBGBugReporting.setFloatingButtonEdge(floatingButtonEdge, offsetFromTop); +}, + + /** + * Sets whether attachments in bug reporting and in-app messaging are enabled or not. + * @param {boolean} screenshot A boolean to enable or disable screenshot attachments. + * @param {boolean} extraScreenshot A boolean to enable or disable extra + * screenshot attachments. + * @param {boolean} galleryImage A boolean to enable or disable gallery image + * attachments. In iOS 10+,NSPhotoLibraryUsageDescription should be set in + * info.plist to enable gallery image attachments. + * @param {boolean} screenRecording A boolean to enable or disable screen recording attachments. + */ + setEnabledAttachmentTypes( + screenshot, + extraScreenshot, + galleryImage, + screenRecording + ) { + IBGBugReporting.setEnabledAttachmentTypes( + screenshot, + extraScreenshot, + galleryImage, + screenRecording + ); + }, + /** * The event used to invoke the feedback form * @readonly diff --git a/package.json b/package.json index f9cbf314c..139741287 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "instabug-reactnative", - "version": "8.5.3", + "version": "8.5.4", "description": "React Native plugin for integrating the Instabug SDK", "main": "index.js", "types": "index.d.ts",