11import {
22 NativeModules ,
3- NativeAppEventEmitter ,
4- DeviceEventEmitter ,
53 Platform
64} from 'react-native' ;
75let { Instabug } = NativeModules ;
86import InstabugModule from '../index' ;
7+ import IBGEventEmitter from '../utils/IBGEventEmitter' ;
8+ import InstabugConstants from '../utils/InstabugConstants' ;
99
1010/**
1111 * BugReporting
@@ -76,23 +76,11 @@ export default {
7676 * Sets a block of code to be executed just before the SDK's UI is presented.
7777 * This block is executed on the UI thread. Could be used for performing any
7878 * UI changes before the SDK's UI is shown.
79- * @param {function } preInvocationHandler - A callback that gets executed before invoking the SDK
79+ * @param {function } handler - A callback that gets executed before invoking the SDK
8080 */
81- onInvokeHandler : function ( preInvocationHandler ) {
82- if ( Platform . OS === 'ios' ) {
83- Instabug . addListener ( 'IBGpreInvocationHandler' ) ;
84- NativeAppEventEmitter . addListener (
85- 'IBGpreInvocationHandler' ,
86- preInvocationHandler
87- ) ;
88- } else {
89- DeviceEventEmitter . addListener (
90- 'IBGpreInvocationHandler' ,
91- preInvocationHandler
92- ) ;
93- }
94-
95- Instabug . setPreInvocationHandler ( preInvocationHandler ) ;
81+ onInvokeHandler : function ( handler ) {
82+ IBGEventEmitter . addListener ( InstabugConstants . ON_INVOKE_HANDLER , handler ) ;
83+ Instabug . setPreInvocationHandler ( handler ) ;
9684 } ,
9785
9886 /**
@@ -111,26 +99,14 @@ export default {
11199 * Sets a block of code to be executed right after the SDK's UI is dismissed.
112100 * This block is executed on the UI thread. Could be used for performing any
113101 * UI changes after the SDK's UI is dismissed.
114- * @param {function } postInvocationHandler - A callback to get executed after
102+ * @param {function } handler - A callback to get executed after
115103 * dismissing the SDK.
116104 */
117- onSDKDismissedHandler : function ( postInvocationHandler ) {
118- if ( Platform . OS === 'ios' ) {
119- Instabug . addListener ( 'IBGpostInvocationHandler' ) ;
120- NativeAppEventEmitter . addListener ( 'IBGpostInvocationHandler' , function (
121- payload
122- ) {
123- postInvocationHandler ( payload [ 'dismissType' ] , payload [ 'reportType' ] ) ;
124- } ) ;
125- } else {
126- DeviceEventEmitter . addListener ( 'IBGpostInvocationHandler' , function (
127- payload
128- ) {
129- postInvocationHandler ( payload . dismissType , payload . reportType ) ;
130- } ) ;
131- }
132-
133- Instabug . setPostInvocationHandler ( postInvocationHandler ) ;
105+ onSDKDismissedHandler : function ( handler ) {
106+ IBGEventEmitter . addListener ( InstabugConstants . ON_SDK_DISMISSED_HANDLER , ( payload ) => {
107+ handler ( payload . dismissType , payload . reportType ) ;
108+ } ) ;
109+ Instabug . setPostInvocationHandler ( handler ) ;
134110 } ,
135111
136112 /**
0 commit comments