Skip to content

Commit 3211429

Browse files
faogustavoa7ul
authored andcommitted
react-native-navigation (wix) fix (#18)
* added forceApplicationToQuit parameter * adapted native module * finish crashed activity after start error activity * Update README.md * Added verification to OS As iOS module did not changed the signature, we will only apply the callback to it, ignoring other parameter that fix the react-native-navigation problem
1 parent 134aed5 commit 3211429

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,14 @@ setNativeExceptionHandler((errorString) => {
381381
*More Examples can be found in the examples folder*
382382
- Preserving old handler (thanks to zeh)
383383

384+
#### react-native-navigation (Wix)
385+
386+
When you use the [wix library](http://wix.github.io/react-native-navigation/) to navigate, you need to add a *false* parameter to _setNativeExceptionHandler_. Otherwise it will recreate the application above the crash screen.
387+
388+
```js
389+
setNativeExceptionHandler(nativeErrorCallback, false);
390+
```
391+
384392

385393
## CONTRIBUTORS
386394
- [Atul R](https://github.com/master-atul)

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class ReactNativeExceptionHandlerModule extends ReactContextBaseJavaModul
1414
private ReactApplicationContext reactContext;
1515
private Activity activity;
1616
private static Class errorIntentTargetClass = DefaultErrorScreen.class;
17+
private boolean forceToQuit;
1718
private Callback callbackHolder;
1819

1920
public ReactNativeExceptionHandlerModule(ReactApplicationContext reactContext) {
@@ -28,21 +29,31 @@ public String getName() {
2829

2930

3031
@ReactMethod
31-
public void setHandlerforNativeException(Callback customHandler){
32-
callbackHolder = customHandler;
32+
public void setHandlerforNativeException(final boolean forceToQuit, Callback customHandler){
33+
this.callbackHolder = customHandler;
34+
this.forceToQuit = forceToQuit;
35+
3336
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
3437
@Override
3538
public void uncaughtException(Thread thread, Throwable throwable) {
3639
activity = getCurrentActivity();
3740
String stackTraceString = Log.getStackTraceString(throwable);
3841
callbackHolder.invoke(stackTraceString);
39-
Log.d("ERROR",stackTraceString);
42+
43+
if (BuildConfig.DEBUG) {
44+
Log.d("ERROR",stackTraceString);
45+
}
46+
4047
Intent i = new Intent();
4148
i.setClass(activity, errorIntentTargetClass);
4249
i.putExtra("stack_trace_string",stackTraceString);
4350
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
51+
4452
activity.startActivity(i);
45-
System.exit(0);
53+
activity.finish();
54+
55+
if (forceToQuit)
56+
System.exit(0);
4657
}
4758
});
4859
}

index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import {NativeModules} from 'react-native';
2+
import {NativeModules, Platform} from 'react-native';
33

44
const {ReactNativeExceptionHandler} = NativeModules;
55

@@ -17,11 +17,16 @@ export const setJSExceptionHandler = (customHandler = noop, allowedInDevMode = f
1717

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

20-
export const setNativeExceptionHandler = (customErrorHandler = noop) => {
20+
export const setNativeExceptionHandler = (customErrorHandler = noop, forceApplicationToQuit = true) => {
2121
if (typeof customErrorHandler !== 'function') {
2222
customErrorHandler = noop;
2323
}
24-
ReactNativeExceptionHandler.setHandlerforNativeException(customErrorHandler);
24+
25+
if (Platform.OS === 'ios') {
26+
ReactNativeExceptionHandler.setHandlerforNativeException(customErrorHandler);
27+
} else {
28+
ReactNativeExceptionHandler.setHandlerforNativeException(forceApplicationToQuit, customErrorHandler);
29+
}
2530
};
2631

2732
export default {

0 commit comments

Comments
 (0)