Display red screen error in react native from a native module

298 Views Asked by At

I implemented a native module and I would like to display an error for a developer using the redbox error screen from the native module. This error will inform about obsolete values.

Does anyone know, how to display this kind of screen with a custom message?

Below I am attaching a screenshot, what I would like to achieve:

1

There are 1 best solutions below

0
On

On android you can achieve this with the following code:

val exceptionManager = reactContext.getNativeModule(ExceptionsManagerModule::class.java)
val error: WritableMap = WritableNativeMap()
error.putString("message", "Error message")
exceptionManager.reportException(error)

on iOS it's also quite straightforward:

let exceptionsManager = bridge.module(forName: "RCTExceptionsManager") as? exceptionsManager
exceptionsManager?.reportFatalException("message", stack: nil, exceptionId: 1)