Skip to content

Commit 6e19ace

Browse files
Enable SetPreInvocationHandler API for android
and add missing imports
1 parent 402eb20 commit 6e19ace

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

InstabugSample/index.android.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export default class InstabugSample extends Component {
2727
super(props);
2828
Instabug.startWithToken('0f0dc916bd9175e3b5d2fdf0cfa49a69',
2929
Instabug.invocationEvent.floatingButton);
30+
Instabug.setPreInvocationHandler(() => {
31+
Alert.alert("PreInvocationEvent", "Done :) ");
32+
});
3033
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
3134
this.state = {
3235
dataSource: ds.cloneWithRows(this._genRows({})),

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
import com.instabug.library.InstabugCustomTextPlaceHolder;
2525
import com.instabug.library.user.UserEventParam;
2626

27+
import com.instabug.reactlibrary.utils.ArrayUtil;
28+
import com.instabug.reactlibrary.utils.MapUtil;
29+
2730
import java.util.ArrayList;
2831
import java.util.HashMap;
2932
import java.util.Locale;
@@ -875,7 +878,28 @@ public void logUserEventWithNameAndParams(String name, ReadableMap params) {
875878
}
876879
}
877880

878-
881+
/**
882+
* Sets a block of code to be executed just before the SDK's UI is presented.
883+
* This block is executed on the UI thread. Could be used for performing any
884+
* UI changes before the SDK's UI is shown.
885+
*
886+
* @param {preInvocationHandler} preInvocationHandler - A callback that gets executed before
887+
* invoking the SDK
888+
*/
889+
@ReactMethod
890+
public void setPreInvocationHandler(final Callback preInvocationHandler) {
891+
try {
892+
Runnable preInvocationRunnable = new Runnable() {
893+
@Override
894+
public void run() {
895+
preInvocationHandler.invoke();
896+
}
897+
};
898+
mInstabug.setPreInvocation(preInvocationRunnable);
899+
} catch (java.lang.Exception exception) {
900+
exception.printStackTrace();
901+
}
902+
}
879903

880904
private InstabugCustomTextPlaceHolder.Key getStringToKeyConstant(String key) {
881905
String keyInLowerCase = key.toLowerCase();

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ module.exports = {
126126
'IBGpreInvocationHandler',
127127
preInvocationHandler
128128
);
129-
130-
Instabug.setPreInvocationHandler(preInvocationHandler);
131129
}
130+
131+
Instabug.setPreInvocationHandler(preInvocationHandler);
132+
132133
},
133134

134135
/**

0 commit comments

Comments
 (0)