From 9d56c07bea3a3af7f51e615308698f35b197a759 Mon Sep 17 00:00:00 2001 From: Emily Janzer Date: Mon, 6 Apr 2020 11:32:46 -0700 Subject: [PATCH] Add API for getting sourceURL directly from ReactContext Summary: In bridgeless mode, the CatalystInstance doesn't exist, but we still need to be able to access the sourceURL in SourceCodeModule (which is needed to render the images in LogBox warnings and errors). This diff adds a new API for getting the sourceURL directly from ReactContext, instead of having to call context.getCatalystInstance().getSourceURL(), and updates SourceCodeModule to use it. Changelog: [Internal] Reviewed By: RSNara Differential Revision: D20848700 fbshipit-source-id: 3ecda81a17121178b76bbb3e9b0f27f103c1961a --- .../java/com/facebook/react/bridge/ReactContext.java | 10 ++++++++++ .../facebook/react/modules/debug/SourceCodeModule.java | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java index b645d997172..fe13dd68981 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java @@ -455,4 +455,14 @@ public class ReactContext extends ContextWrapper { } return mCatalystInstance.getJSIModule(moduleType); } + + /** + * Get the sourceURL for the JS bundle from the CatalystInstance. This method is needed for + * compatibility with bridgeless mode, which has no CatalystInstance. + * + * @return The JS bundle URL set when the bundle was loaded + */ + public @Nullable String getSourceURL() { + return mCatalystInstance.getSourceURL(); + } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/debug/SourceCodeModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/debug/SourceCodeModule.java index 315189544d8..88ee3dbedf4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/debug/SourceCodeModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/debug/SourceCodeModule.java @@ -37,7 +37,7 @@ public class SourceCodeModule extends NativeSourceCodeSpec { String sourceURL = Assertions.assertNotNull( - getReactApplicationContext().getCatalystInstance().getSourceURL(), + getReactApplicationContext().getSourceURL(), "No source URL loaded, have you initialised the instance?"); constants.put("scriptURL", sourceURL);