mirror of
https://github.com/status-im/instabug-reactnative.git
synced 2025-03-01 05:30:42 +00:00
Updating event handlers and main thread operations
This commit is contained in:
parent
ec0f3c87c1
commit
86c817d512
37
index.js
37
index.js
@ -4,7 +4,7 @@
|
|||||||
* @flow
|
* @flow
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { NativeModules } from 'react-native';
|
import { NativeModules, NativeAppEventEmitter } from 'react-native';
|
||||||
|
|
||||||
let {Instabug} = NativeModules;
|
let {Instabug} = NativeModules;
|
||||||
|
|
||||||
@ -59,6 +59,7 @@ module.exports = {
|
|||||||
* @param {string} fileLocation Path to a file that's going to be attached
|
* @param {string} fileLocation Path to a file that's going to be attached
|
||||||
* to each report.
|
* to each report.
|
||||||
*/
|
*/
|
||||||
|
// Not yet testsed
|
||||||
setFileAttachment: function(fileLocation) {
|
setFileAttachment: function(fileLocation) {
|
||||||
Instabug.setFileAttachment(fileLocation);
|
Instabug.setFileAttachment(fileLocation);
|
||||||
},
|
},
|
||||||
@ -78,6 +79,7 @@ module.exports = {
|
|||||||
* Adds custom logs that will be sent with each report.
|
* Adds custom logs that will be sent with each report.
|
||||||
* @param {string} log Message to be logged.
|
* @param {string} log Message to be logged.
|
||||||
*/
|
*/
|
||||||
|
// Needs renaming
|
||||||
IBGLog: function(log) {
|
IBGLog: function(log) {
|
||||||
Instabug.IBGLog(log);
|
Instabug.IBGLog(log);
|
||||||
},
|
},
|
||||||
@ -103,6 +105,12 @@ module.exports = {
|
|||||||
* report.
|
* report.
|
||||||
*/
|
*/
|
||||||
setPreSendingHandler: function(handler) {
|
setPreSendingHandler: function(handler) {
|
||||||
|
Instabug.addListener('IBGpreSendingHandler');
|
||||||
|
NativeAppEventEmitter.addListener(
|
||||||
|
'IBGpreSendingHandler',
|
||||||
|
handler
|
||||||
|
);
|
||||||
|
|
||||||
Instabug.setPreSendingHandler(handler);
|
Instabug.setPreSendingHandler(handler);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -113,6 +121,12 @@ module.exports = {
|
|||||||
* @callback handler - A callback that gets executed before sending each bug report.
|
* @callback handler - A callback that gets executed before sending each bug report.
|
||||||
*/
|
*/
|
||||||
setPreInvocationHandler: function(handler) {
|
setPreInvocationHandler: function(handler) {
|
||||||
|
Instabug.addListener('IBGpreInvocationHandler');
|
||||||
|
NativeAppEventEmitter.addListener(
|
||||||
|
'IBGpreInvocationHandler',
|
||||||
|
handler
|
||||||
|
);
|
||||||
|
|
||||||
Instabug.setPreInvocationHandler(handler);
|
Instabug.setPreInvocationHandler(handler);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -121,12 +135,20 @@ module.exports = {
|
|||||||
* This block is executed on the UI thread. Could be used for performing any
|
* This block is executed on the UI thread. Could be used for performing any
|
||||||
* UI changes after the SDK's UI is dismissed.
|
* UI changes after the SDK's UI is dismissed.
|
||||||
* @callback handler - A callback that gets executed 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.dismissType} dismissType How the SDK was dismissed.
|
||||||
* @param {constants.reportType} Type of report that has been sent. Will be set
|
* @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
|
* to IBGReportTypeBug in case the SDK has been dismissed without selecting a
|
||||||
* report type, so you might need to check issueState before reportType
|
* report type, so you might need to check issueState before reportType
|
||||||
*/
|
*/
|
||||||
setPostInvocatioHandler: function(handler) {
|
setPostInvocatioHandler: function(handler) {
|
||||||
|
Instabug.addListener('IBGpostInvocationHandler');
|
||||||
|
NativeAppEventEmitter.addListener(
|
||||||
|
'IBGpostInvocationHandler',
|
||||||
|
function(payload) {
|
||||||
|
handler(payload['dismissType'], payload['reportType']);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
Instabug.setPostInvocatioHandler(handler);
|
Instabug.setPostInvocatioHandler(handler);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -165,6 +187,7 @@ module.exports = {
|
|||||||
* shown or not. Passing YES will show screenshot view for both feedback and
|
* shown or not. Passing YES will show screenshot view for both feedback and
|
||||||
* bug reporting, while passing NO will disable it for both.
|
* bug reporting, while passing NO will disable it for both.
|
||||||
*/
|
*/
|
||||||
|
// Doesn't work on existing SDK
|
||||||
setWillSkipScreenshotAnnotation: function(willSkipeScreenshotAnnotation) {
|
setWillSkipScreenshotAnnotation: function(willSkipeScreenshotAnnotation) {
|
||||||
Instabug.setWillSkipScreenshotAnnotation(willSkipeScreenshotAnnotation);
|
Instabug.setWillSkipScreenshotAnnotation(willSkipeScreenshotAnnotation);
|
||||||
},
|
},
|
||||||
@ -197,6 +220,7 @@ module.exports = {
|
|||||||
* @param {boolean} isPushNotificationEnabled A boolean to indicate whether push
|
* @param {boolean} isPushNotificationEnabled A boolean to indicate whether push
|
||||||
* notifications are enabled or disabled.
|
* notifications are enabled or disabled.
|
||||||
*/
|
*/
|
||||||
|
// Not tested
|
||||||
setPushNotificationsEnabled: function(isPushNotificationEnabled) {
|
setPushNotificationsEnabled: function(isPushNotificationEnabled) {
|
||||||
Instabug.setPushNotificationsEnabled(isPushNotificationEnabled);
|
Instabug.setPushNotificationsEnabled(isPushNotificationEnabled);
|
||||||
},
|
},
|
||||||
@ -350,6 +374,7 @@ module.exports = {
|
|||||||
* @param {boolean} isChatNotificationEnabled A boolean to set whether
|
* @param {boolean} isChatNotificationEnabled A boolean to set whether
|
||||||
* notifications are enabled or disabled.
|
* notifications are enabled or disabled.
|
||||||
*/
|
*/
|
||||||
|
// Not tested
|
||||||
setChatNotificationEnabled: function(isChatNotificationEnabled) {
|
setChatNotificationEnabled: function(isChatNotificationEnabled) {
|
||||||
Instabug.setChatNotificationEnabled(isChatNotificationEnabled);
|
Instabug.setChatNotificationEnabled(isChatNotificationEnabled);
|
||||||
},
|
},
|
||||||
@ -360,6 +385,12 @@ module.exports = {
|
|||||||
* is received.
|
* is received.
|
||||||
*/
|
*/
|
||||||
setOnNewMessageHandler: function(handler) {
|
setOnNewMessageHandler: function(handler) {
|
||||||
|
Instabug.addListener('IBGonNewMessageHandler');
|
||||||
|
NativeAppEventEmitter.addListener(
|
||||||
|
'IBGonNewMessageHandler',
|
||||||
|
handler
|
||||||
|
);
|
||||||
|
|
||||||
Instabug.setOnNewMessageHandler(handler);
|
Instabug.setOnNewMessageHandler(handler);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Binary file not shown.
@ -8,7 +8,8 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "RCTBridgeModule.h"
|
#import "RCTBridgeModule.h"
|
||||||
|
#import "RCTEventEmitter.h"
|
||||||
|
|
||||||
@interface InstabugReactBridge : NSObject <RCTBridgeModule>
|
@interface InstabugReactBridge : RCTEventEmitter <RCTBridgeModule>
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -11,28 +11,35 @@
|
|||||||
|
|
||||||
@implementation InstabugReactBridge
|
@implementation InstabugReactBridge
|
||||||
|
|
||||||
|
- (NSArray<NSString *> *)supportedEvents {
|
||||||
|
return @[
|
||||||
|
@"IBGpreSendingHandler",
|
||||||
|
@"IBGpreInvocationHandler",
|
||||||
|
@"IBGpostInvocationHandler",
|
||||||
|
@"IBGonNewMessageHandler"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
RCT_EXPORT_MODULE(Instabug)
|
RCT_EXPORT_MODULE(Instabug)
|
||||||
|
|
||||||
|
- (dispatch_queue_t)methodQueue {
|
||||||
|
return dispatch_get_main_queue();
|
||||||
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(startWithToken:(NSString *)token invocationEvent:(IBGInvocationEvent)invocationEvent) {
|
RCT_EXPORT_METHOD(startWithToken:(NSString *)token invocationEvent:(IBGInvocationEvent)invocationEvent) {
|
||||||
[Instabug startWithToken:token invocationEvent:invocationEvent];
|
[Instabug startWithToken:token invocationEvent:invocationEvent];
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(invoke) {
|
RCT_EXPORT_METHOD(invoke) {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
[Instabug invoke];
|
[Instabug invoke];
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(invokeWithInvocationMode:(IBGInvocationMode)invocationMode) {
|
RCT_EXPORT_METHOD(invokeWithInvocationMode:(IBGInvocationMode)invocationMode) {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
[Instabug invokeWithInvocationMode:invocationMode];
|
[Instabug invokeWithInvocationMode:invocationMode];
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(dismiss) {
|
RCT_EXPORT_METHOD(dismiss) {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
[Instabug dismiss];
|
[Instabug dismiss];
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(setFileAttachment:(NSString *)fileLocation) {
|
RCT_EXPORT_METHOD(setFileAttachment:(NSString *)fileLocation) {
|
||||||
@ -48,39 +55,44 @@ RCT_EXPORT_METHOD(IBGLog:(NSString *)log) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(setUserStepsEnabled:(BOOL)isUserStepsEnabled) {
|
RCT_EXPORT_METHOD(setUserStepsEnabled:(BOOL)isUserStepsEnabled) {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
[Instabug setUserStepsEnabled:isUserStepsEnabled];
|
[Instabug setUserStepsEnabled:isUserStepsEnabled];
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(setPreSendingHandler:(RCTResponseSenderBlock)callBack) {
|
RCT_EXPORT_METHOD(setPreSendingHandler:(RCTResponseSenderBlock)callBack) {
|
||||||
if (callBack != nil) {
|
if (callBack != nil) {
|
||||||
[Instabug setPreSendingHandler:^{
|
[Instabug setPreSendingHandler:^{
|
||||||
callBack(@[]);
|
[self sendEventWithName:@"IBGpreSendingHandler" body:nil];
|
||||||
}];
|
}];
|
||||||
|
} else {
|
||||||
|
[Instabug setPreSendingHandler:nil];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(setPreInvocationHandler:(RCTResponseSenderBlock)callBack) {
|
RCT_EXPORT_METHOD(setPreInvocationHandler:(RCTResponseSenderBlock)callBack) {
|
||||||
if (callBack != nil) {
|
if (callBack != nil) {
|
||||||
[Instabug setPreInvocationHandler:^{
|
[Instabug setPreInvocationHandler:^{
|
||||||
callBack(@[]);
|
[self sendEventWithName:@"IBGpreInvocationHandler" body:nil];
|
||||||
}];
|
}];
|
||||||
|
} else {
|
||||||
|
[Instabug setPreInvocationHandler:nil];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(setPostInvocatioHandler:(RCTResponseSenderBlock)callBack) {
|
RCT_EXPORT_METHOD(setPostInvocatioHandler:(RCTResponseSenderBlock)callBack) {
|
||||||
if (callBack != nil) {
|
if (callBack != nil) {
|
||||||
[Instabug setPostInvocatioHandler:^(IBGDismissType dismissType, IBGReportType reportType) {
|
[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) {
|
RCT_EXPORT_METHOD(showIntroMessage) {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
[Instabug showIntroMessage];
|
[Instabug showIntroMessage];
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(setUserEmail:(NSString *)userEmail) {
|
RCT_EXPORT_METHOD(setUserEmail:(NSString *)userEmail) {
|
||||||
@ -172,7 +184,13 @@ RCT_EXPORT_METHOD(setChatNotificationEnabled:(BOOL)isChatNotificationEnabled) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(setOnNewMessageHandler:(RCTResponseSenderBlock)callBack) {
|
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
|
RCT_EXPORT_METHOD(setPromptOptions:(BOOL)bugReportEnabled
|
||||||
@ -202,6 +220,13 @@ RCT_EXPORT_METHOD(isInstabugNotification:(NSDictionary *)notification callback:(
|
|||||||
@"invocationModeNewChat": @(IBGInvocationModeNewChat),
|
@"invocationModeNewChat": @(IBGInvocationModeNewChat),
|
||||||
@"invocationModeChatsList": @(IBGInvocationModeChatsList),
|
@"invocationModeChatsList": @(IBGInvocationModeChatsList),
|
||||||
|
|
||||||
|
@"dismissTypeSubmit": @(IBGDismissTypeSubmit),
|
||||||
|
@"dismissTypeCancel": @(IBGDismissTypeCancel),
|
||||||
|
@"dismissTypeAddAtttachment": @(IBGDismissTypeAddAttachment),
|
||||||
|
|
||||||
|
@"reportTypeBug": @(IBGReportTypeBug),
|
||||||
|
@"reportTypeFeedback": @(IBGReportTypeFeedback),
|
||||||
|
|
||||||
@"rectMinXEdge": @(CGRectMinXEdge),
|
@"rectMinXEdge": @(CGRectMinXEdge),
|
||||||
@"rectMinYEdge": @(CGRectMinYEdge),
|
@"rectMinYEdge": @(CGRectMinYEdge),
|
||||||
@"rectMaxXEdge": @(CGRectMaxXEdge),
|
@"rectMaxXEdge": @(CGRectMaxXEdge),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user