Check bridgeless mode in getReactApplicationContextIfActiveOrWarn

Summary:
We currently have a method in ReactContextBaseJavaModule that logs a warning if the native module is trying to access a ReactContext without an active Catalyst instance (because if you try to access it directly, it throws).

For bridgeless mode, we never have a CatalystInstance, but it's safe to call certain methods on the context that would normally require one. For this case, let's just return the context when the context is in bridgeless mode.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D19133988

fbshipit-source-id: cae0bd397aa24d9ad416491cbc32676870cc70b0
This commit is contained in:
Emily Janzer
2019-12-17 18:38:57 -08:00
committed by Facebook Github Bot
parent 37ff892e24
commit 636f48de89
@@ -52,7 +52,8 @@ public abstract class ReactContextBaseJavaModule extends BaseJavaModule {
*/
@ThreadConfined(ANY)
protected @Nullable final ReactApplicationContext getReactApplicationContextIfActiveOrWarn() {
if (mReactApplicationContext.hasActiveCatalystInstance()) {
if (mReactApplicationContext.hasActiveCatalystInstance()
|| mReactApplicationContext.isBridgeless()) {
return mReactApplicationContext;
}