Files
react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstance.java
T
Ashok Menon 89d72c99be BREAKING - (Re)moving JSBundleLoader.getSourceUrl()
Summary:
== What ==

Changing the `JSBundleLoader` API, to remove `String getSourceUrl()`, instead `JSBundleLoader.loadScript` now returns the source URL it loaded.

This change has a knock-on effect: We can no longer populate `SourceCodeModule` when we construct it, because at that time, we do not know the source URL.

In order to solve this I have made the following changes:

 -  Added `CatalystInstance.getSourceURL()`, to return the source URL from the instance after the JS Bundle has been loaded, or `null` otherwise.
 -  Removed `ReactInstanceManager.getSourceUrl()`, because its only purpose was to populate `SourceCodeModule`.
 -  Also removed `ReactInstanceManager.getJSBundleFile()` because it was only being used in a test confirming that the `ReactInstanceManager` knew its bundle file as soon as it was constructed, which is no longer necessarily true.
 -  Initialise `SourceCodeModule` with the `ReactContext` instance it belongs to.
 -  Override `NativeModule.initialize()` in `SourceCodeModule` to fetch the source URL. When the `SourceCodeModule` is constructed, the context does not have a properly initialised `CatalystInstance`, but by the time we call initialise on it, the `ReactContext` has a `CatalystInstance` and that in turn has a source URL.

== Why ==

The reason for this change is that it allows us to add implementations of `JSBundleLoader`, that cannot determine their source URL until after having performed a load successfully. In particular I plan to introduce `FallbackJSBundleLoader` which will try to load from multiple sources in sequence stopping after the first successful load. As load failures could happen for a variety of reasons, we can't know what the true source URL is without performing the load.

Reviewed By: javache

Differential Revision: D4398956

fbshipit-source-id: 51ff4e289c8723e9d242f23267181c775a6abe6f
2017-01-13 03:58:47 -08:00

93 lines
3.2 KiB
Java

/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.bridge;
import javax.annotation.Nullable;
import java.util.Collection;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.queue.ReactQueueConfiguration;
import com.facebook.react.common.annotations.VisibleForTesting;
/**
* A higher level API on top of the asynchronous JSC bridge. This provides an
* environment allowing the invocation of JavaScript methods and lets a set of
* Java APIs be invokable from JavaScript as well.
*/
@DoNotStrip
public interface CatalystInstance extends MemoryPressureListener {
void runJSBundle();
/**
* Return the source URL of the JS Bundle that was run, or {@code null} if no JS
* bundle has been run yet.
*/
@Nullable String getSourceURL();
// This is called from java code, so it won't be stripped anyway, but proguard will rename it,
// which this prevents.
@DoNotStrip
void invokeCallback(ExecutorToken executorToken, final int callbackID, final NativeArray arguments);
@DoNotStrip
void callFunction(
ExecutorToken executorToken,
String module,
String method,
NativeArray arguments);
/**
* Destroys this catalyst instance, waiting for any other threads in ReactQueueConfiguration
* (besides the UI thread) to finish running. Must be called from the UI thread so that we can
* fully shut down other threads.
*/
void destroy();
boolean isDestroyed();
/**
* Initialize all the native modules
*/
@VisibleForTesting
void initialize();
ReactQueueConfiguration getReactQueueConfiguration();
<T extends JavaScriptModule> T getJSModule(Class<T> jsInterface);
<T extends JavaScriptModule> T getJSModule(ExecutorToken executorToken, Class<T> jsInterface);
<T extends NativeModule> boolean hasNativeModule(Class<T> nativeModuleInterface);
<T extends NativeModule> T getNativeModule(Class<T> nativeModuleInterface);
Collection<NativeModule> getNativeModules();
/**
* Adds a idle listener for this Catalyst instance. The listener will receive notifications
* whenever the bridge transitions from idle to busy and vice-versa, where the busy state is
* defined as there being some non-zero number of calls to JS that haven't resolved via a
* onBatchCompleted call. The listener should be purely passive and not affect application logic.
*/
void addBridgeIdleDebugListener(NotThreadSafeBridgeIdleDebugListener listener);
/**
* Removes a NotThreadSafeBridgeIdleDebugListener previously added with
* {@link #addBridgeIdleDebugListener}
*/
void removeBridgeIdleDebugListener(NotThreadSafeBridgeIdleDebugListener listener);
boolean supportsProfiling();
void startProfiler(String title);
void stopProfiler(String title, String filename);
@VisibleForTesting
void setGlobalVariable(String propName, String jsonValue);
/**
* Get the C pointer (as a long) to the JavaScriptCore context associated with this instance.
*/
long getJavaScriptContext();
}