Skip to content

Commit 10728e9

Browse files
committed
Fix Android parameters ordering
The current implementation raises "cannot have non-function argument after a function arg" as of RN v0.48+. This patch fixes this issue inverting the order of the arguments in the native implementation. Proper checks are in place to make this change backward compatible and detect the previous API usage, switching the parameters as needed.
1 parent 26f57c6 commit 10728e9

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

android/src/main/java/com/masteratul/exceptionhandler/ReactNativeExceptionHandlerModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public String getName() {
2828

2929

3030
@ReactMethod
31-
public void setHandlerforNativeException(Callback customHandler, final boolean forceToQuit){
31+
public void setHandlerforNativeException(final boolean forceToQuit, Callback customHandler){
3232
callbackHolder = customHandler;
3333

3434
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,28 @@ export const setJSExceptionHandler = (customHandler = noop, allowedInDevMode = f
1717

1818
export const getJSExceptionHandler = () => global.ErrorUtils.getGlobalHandler();
1919

20-
export const setNativeExceptionHandler = (customErrorHandler = noop, forceApplicationToQuit = true) => {
20+
export const setNativeExceptionHandler = (forceApplicationToQuit = true, customErrorHandler = noop) => {
21+
var handler = customErrorHandler;
22+
23+
// backward compatible API
24+
if (typeof forceApplicationToQuit === 'function') {
25+
handler = forceApplicationToQuit;
26+
}
27+
28+
if (typeof customErrorHandler === 'boolean') {
29+
forceApplicationToQuit = customErrorHandler;
30+
}
31+
32+
customErrorHandler = handler;
33+
2134
if (typeof customErrorHandler !== 'function') {
2235
customErrorHandler = noop;
2336
}
2437

2538
if (Platform.OS === 'ios') {
2639
ReactNativeExceptionHandler.setHandlerforNativeException(customErrorHandler);
2740
} else {
28-
ReactNativeExceptionHandler.setHandlerforNativeException(customErrorHandler, forceApplicationToQuit);
41+
ReactNativeExceptionHandler.setHandlerforNativeException(forceApplicationToQuit, customErrorHandler);
2942
}
3043
};
3144

0 commit comments

Comments
 (0)