diff --git a/index.js b/index.js index b41810d..1041cfa 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ * @flow */ -import { NativeModules } from 'react-native'; +import { NativeModules, NativeAppEventEmitter } from 'react-native'; let {Instabug} = NativeModules; @@ -59,6 +59,7 @@ module.exports = { * @param {string} fileLocation Path to a file that's going to be attached * to each report. */ + // Not yet testsed setFileAttachment: function(fileLocation) { Instabug.setFileAttachment(fileLocation); }, @@ -78,6 +79,7 @@ module.exports = { * Adds custom logs that will be sent with each report. * @param {string} log Message to be logged. */ + // Needs renaming IBGLog: function(log) { Instabug.IBGLog(log); }, @@ -103,6 +105,12 @@ module.exports = { * report. */ setPreSendingHandler: function(handler) { + Instabug.addListener('IBGpreSendingHandler'); + NativeAppEventEmitter.addListener( + 'IBGpreSendingHandler', + handler + ); + Instabug.setPreSendingHandler(handler); }, @@ -113,6 +121,12 @@ module.exports = { * @callback handler - A callback that gets executed before sending each bug report. */ setPreInvocationHandler: function(handler) { + Instabug.addListener('IBGpreInvocationHandler'); + NativeAppEventEmitter.addListener( + 'IBGpreInvocationHandler', + handler + ); + Instabug.setPreInvocationHandler(handler); }, @@ -121,12 +135,20 @@ module.exports = { * This block is executed on the UI thread. Could be used for performing any * UI changes after the SDK's UI is dismissed. * @callback handler - A callback that gets executed after the SDK's UI is dismissed. - * @param {constants.dismissType} How the SDK was dismissed. - * @param {constants.reportType} Type of report that has been sent. Will be set + * @param {constants.dismissType} dismissType How the SDK was dismissed. + * @param {constants.reportType} reportType Type of report that has been sent. Will be set * to IBGReportTypeBug in case the SDK has been dismissed without selecting a * report type, so you might need to check issueState before reportType */ setPostInvocatioHandler: function(handler) { + Instabug.addListener('IBGpostInvocationHandler'); + NativeAppEventEmitter.addListener( + 'IBGpostInvocationHandler', + function(payload) { + handler(payload['dismissType'], payload['reportType']); + } + ); + Instabug.setPostInvocatioHandler(handler); }, @@ -165,6 +187,7 @@ module.exports = { * shown or not. Passing YES will show screenshot view for both feedback and * bug reporting, while passing NO will disable it for both. */ + // Doesn't work on existing SDK setWillSkipScreenshotAnnotation: function(willSkipeScreenshotAnnotation) { Instabug.setWillSkipScreenshotAnnotation(willSkipeScreenshotAnnotation); }, @@ -197,6 +220,7 @@ module.exports = { * @param {boolean} isPushNotificationEnabled A boolean to indicate whether push * notifications are enabled or disabled. */ + // Not tested setPushNotificationsEnabled: function(isPushNotificationEnabled) { Instabug.setPushNotificationsEnabled(isPushNotificationEnabled); }, @@ -350,6 +374,7 @@ module.exports = { * @param {boolean} isChatNotificationEnabled A boolean to set whether * notifications are enabled or disabled. */ + // Not tested setChatNotificationEnabled: function(isChatNotificationEnabled) { Instabug.setChatNotificationEnabled(isChatNotificationEnabled); }, @@ -360,6 +385,12 @@ module.exports = { * is received. */ setOnNewMessageHandler: function(handler) { + Instabug.addListener('IBGonNewMessageHandler'); + NativeAppEventEmitter.addListener( + 'IBGonNewMessageHandler', + handler + ); + Instabug.setOnNewMessageHandler(handler); }, diff --git a/ios/RNInstabug.xcodeproj/project.xcworkspace/xcuserdata/yousefhamza.xcuserdatad/UserInterfaceState.xcuserstate b/ios/RNInstabug.xcodeproj/project.xcworkspace/xcuserdata/yousefhamza.xcuserdatad/UserInterfaceState.xcuserstate index 0594eed..ba5f6d7 100644 Binary files a/ios/RNInstabug.xcodeproj/project.xcworkspace/xcuserdata/yousefhamza.xcuserdatad/UserInterfaceState.xcuserstate and b/ios/RNInstabug.xcodeproj/project.xcworkspace/xcuserdata/yousefhamza.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ios/RNInstabug/InstabugReactBridge.h b/ios/RNInstabug/InstabugReactBridge.h index 5fd3631..5866ea1 100644 --- a/ios/RNInstabug/InstabugReactBridge.h +++ b/ios/RNInstabug/InstabugReactBridge.h @@ -8,7 +8,8 @@ #import #import "RCTBridgeModule.h" +#import "RCTEventEmitter.h" -@interface InstabugReactBridge : NSObject +@interface InstabugReactBridge : RCTEventEmitter @end diff --git a/ios/RNInstabug/InstabugReactBridge.m b/ios/RNInstabug/InstabugReactBridge.m index e22b4bf..b14be4c 100644 --- a/ios/RNInstabug/InstabugReactBridge.m +++ b/ios/RNInstabug/InstabugReactBridge.m @@ -11,28 +11,35 @@ @implementation InstabugReactBridge +- (NSArray *)supportedEvents { + return @[ + @"IBGpreSendingHandler", + @"IBGpreInvocationHandler", + @"IBGpostInvocationHandler", + @"IBGonNewMessageHandler" + ]; +} + RCT_EXPORT_MODULE(Instabug) +- (dispatch_queue_t)methodQueue { + return dispatch_get_main_queue(); +} + RCT_EXPORT_METHOD(startWithToken:(NSString *)token invocationEvent:(IBGInvocationEvent)invocationEvent) { [Instabug startWithToken:token invocationEvent:invocationEvent]; } RCT_EXPORT_METHOD(invoke) { - dispatch_async(dispatch_get_main_queue(), ^{ - [Instabug invoke]; - }); + [Instabug invoke]; } RCT_EXPORT_METHOD(invokeWithInvocationMode:(IBGInvocationMode)invocationMode) { - dispatch_async(dispatch_get_main_queue(), ^{ - [Instabug invokeWithInvocationMode:invocationMode]; - }); + [Instabug invokeWithInvocationMode:invocationMode]; } RCT_EXPORT_METHOD(dismiss) { - dispatch_async(dispatch_get_main_queue(), ^{ - [Instabug dismiss]; - }); + [Instabug dismiss]; } RCT_EXPORT_METHOD(setFileAttachment:(NSString *)fileLocation) { @@ -48,39 +55,44 @@ RCT_EXPORT_METHOD(IBGLog:(NSString *)log) { } RCT_EXPORT_METHOD(setUserStepsEnabled:(BOOL)isUserStepsEnabled) { - dispatch_async(dispatch_get_main_queue(), ^{ - [Instabug setUserStepsEnabled:isUserStepsEnabled]; - }); + [Instabug setUserStepsEnabled:isUserStepsEnabled]; } RCT_EXPORT_METHOD(setPreSendingHandler:(RCTResponseSenderBlock)callBack) { if (callBack != nil) { [Instabug setPreSendingHandler:^{ - callBack(@[]); + [self sendEventWithName:@"IBGpreSendingHandler" body:nil]; }]; + } else { + [Instabug setPreSendingHandler:nil]; } } RCT_EXPORT_METHOD(setPreInvocationHandler:(RCTResponseSenderBlock)callBack) { if (callBack != nil) { [Instabug setPreInvocationHandler:^{ - callBack(@[]); + [self sendEventWithName:@"IBGpreInvocationHandler" body:nil]; }]; + } else { + [Instabug setPreInvocationHandler:nil]; } } RCT_EXPORT_METHOD(setPostInvocatioHandler:(RCTResponseSenderBlock)callBack) { if (callBack != nil) { [Instabug setPostInvocatioHandler:^(IBGDismissType dismissType, IBGReportType reportType) { - callBack(@[@(dismissType), @(reportType)]); + [self sendEventWithName:@"IBGpostInvocationHandler" body:@{ + @"dismissType": @(dismissType), + @"reportType": @(reportType) + }]; }]; + } else { + [Instabug setPostInvocatioHandler:nil]; } } RCT_EXPORT_METHOD(showIntroMessage) { - dispatch_async(dispatch_get_main_queue(), ^{ - [Instabug showIntroMessage]; - }); + [Instabug showIntroMessage]; } RCT_EXPORT_METHOD(setUserEmail:(NSString *)userEmail) { @@ -172,7 +184,13 @@ RCT_EXPORT_METHOD(setChatNotificationEnabled:(BOOL)isChatNotificationEnabled) { } RCT_EXPORT_METHOD(setOnNewMessageHandler:(RCTResponseSenderBlock)callBack) { - [Instabug setOnNewMessageHandler:callBack]; + if (callBack != nil) { + [Instabug setOnNewMessageHandler:^{ + [self sendEventWithName:@"IBGonNewMessageHandler" body:nil]; + }]; + } else { + [Instabug setOnNewMessageHandler:nil]; + } } RCT_EXPORT_METHOD(setPromptOptions:(BOOL)bugReportEnabled @@ -202,6 +220,13 @@ RCT_EXPORT_METHOD(isInstabugNotification:(NSDictionary *)notification callback:( @"invocationModeNewChat": @(IBGInvocationModeNewChat), @"invocationModeChatsList": @(IBGInvocationModeChatsList), + @"dismissTypeSubmit": @(IBGDismissTypeSubmit), + @"dismissTypeCancel": @(IBGDismissTypeCancel), + @"dismissTypeAddAtttachment": @(IBGDismissTypeAddAttachment), + + @"reportTypeBug": @(IBGReportTypeBug), + @"reportTypeFeedback": @(IBGReportTypeFeedback), + @"rectMinXEdge": @(CGRectMinXEdge), @"rectMinYEdge": @(CGRectMinYEdge), @"rectMaxXEdge": @(CGRectMaxXEdge),