Java Code Examples for com.facebook.react.bridge.JSBundleLoader

The following are top voted examples for showing how to use com.facebook.react.bridge.JSBundleLoader. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: ReactNativeSignatureExample   File: ReactInstanceManagerImpl.java   View source code 6 votes vote down vote up
private void recreateReactContextInBackground(
    JavaScriptExecutor.Factory jsExecutorFactory,
    JSBundleLoader jsBundleLoader) {
  UiThreadUtil.assertOnUiThread();

  ReactContextInitParams initParams =
      new ReactContextInitParams(jsExecutorFactory, jsBundleLoader);
  if (mReactContextInitAsyncTask == null) {
    // No background task to create react context is currently running, create and execute one.
    mReactContextInitAsyncTask = new ReactContextInitAsyncTask();
    mReactContextInitAsyncTask.execute(initParams);
  } else {
    // Background task is currently running, queue up most recent init params to recreate context
    // once task completes.
    mPendingReactContextInitParams = initParams;
  }
}
 
Example 2
Project: ReactNativeSignatureExample   File: ReactTestHelper.java   View source code 6 votes vote down vote up
@Override
public CatalystInstance build() {
  return new CatalystInstanceImpl.Builder()
    .setReactQueueConfigurationSpec(ReactQueueConfigurationSpec.createDefault())
    .setJSExecutor(new JSCJavaScriptExecutor(new WritableNativeMap()))
    .setRegistry(mNativeModuleRegistryBuilder.build())
    .setJSModulesConfig(mJSModulesConfigBuilder.build())
    .setJSBundleLoader(JSBundleLoader.createFileLoader(
                         mContext,
                         "assets://AndroidTestBundle.js"))
    .setNativeModuleCallExceptionHandler(
      new NativeModuleCallExceptionHandler() {
          @Override
          public void handleException(Exception e) {
            throw new RuntimeException(e);
          }
      })
    .build();
}
 
Example 3
Project: react-native-ibeacon-android   File: ReactInstanceManagerImpl.java   View source code 6 votes vote down vote up
private void recreateReactContextInBackground(
    JavaScriptExecutor.Factory jsExecutorFactory,
    JSBundleLoader jsBundleLoader) {
  UiThreadUtil.assertOnUiThread();

  ReactContextInitParams initParams =
      new ReactContextInitParams(jsExecutorFactory, jsBundleLoader);
  if (mReactContextInitAsyncTask == null) {
    // No background task to create react context is currently running, create and execute one.
    mReactContextInitAsyncTask = new ReactContextInitAsyncTask();
    mReactContextInitAsyncTask.execute(initParams);
  } else {
    // Background task is currently running, queue up most recent init params to recreate context
    // once task completes.
    mPendingReactContextInitParams = initParams;
  }
}
 
Example 4
Project: react-native-ibeacon-android   File: ReactTestHelper.java   View source code 6 votes vote down vote up
@Override
public CatalystInstance build() {
  return new CatalystInstanceImpl.Builder()
    .setReactQueueConfigurationSpec(ReactQueueConfigurationSpec.createDefault())
    .setJSExecutor(new JSCJavaScriptExecutor(new WritableNativeMap()))
    .setRegistry(mNativeModuleRegistryBuilder.build())
    .setJSModulesConfig(mJSModulesConfigBuilder.build())
    .setJSBundleLoader(JSBundleLoader.createFileLoader(
                         mContext,
                         "assets://AndroidTestBundle.js"))
    .setNativeModuleCallExceptionHandler(
      new NativeModuleCallExceptionHandler() {
          @Override
          public void handleException(Exception e) {
            throw new RuntimeException(e);
          }
      })
    .build();
}
 
Example 5
Project: react-native-box-loaders   File: ReactInstanceManagerImpl.java   View source code 6 votes vote down vote up
private void recreateReactContextInBackground(
    JavaScriptExecutor.Factory jsExecutorFactory,
    JSBundleLoader jsBundleLoader) {
  UiThreadUtil.assertOnUiThread();

  ReactContextInitParams initParams =
      new ReactContextInitParams(jsExecutorFactory, jsBundleLoader);
  if (mReactContextInitAsyncTask == null) {
    // No background task to create react context is currently running, create and execute one.
    mReactContextInitAsyncTask = new ReactContextInitAsyncTask();
    mReactContextInitAsyncTask.execute(initParams);
  } else {
    // Background task is currently running, queue up most recent init params to recreate context
    // once task completes.
    mPendingReactContextInitParams = initParams;
  }
}
 
Example 6
Project: react-native-box-loaders   File: ReactTestHelper.java   View source code 6 votes vote down vote up
@Override
public CatalystInstance build() {
  return new CatalystInstanceImpl.Builder()
    .setReactQueueConfigurationSpec(ReactQueueConfigurationSpec.createDefault())
    .setJSExecutor(new JSCJavaScriptExecutor(new WritableNativeMap()))
    .setRegistry(mNativeModuleRegistryBuilder.build())
    .setJSModulesConfig(mJSModulesConfigBuilder.build())
    .setJSBundleLoader(JSBundleLoader.createFileLoader(
                         mContext,
                         "assets://AndroidTestBundle.js"))
    .setNativeModuleCallExceptionHandler(
      new NativeModuleCallExceptionHandler() {
          @Override
          public void handleException(Exception e) {
            throw new RuntimeException(e);
          }
      })
    .build();
}
 
Example 7
Project: react-native-update   File: RCTUpdate.java   View source code 6 votes vote down vote up
private void setJSBundle(ReactInstanceManager instanceManager, String latestJSBundleFile) throws IllegalAccessException {
    try {
        JSBundleLoader latestJSBundleLoader;
        if (latestJSBundleFile.toLowerCase().startsWith("assets://")) {
            latestJSBundleLoader = JSBundleLoader.createAssetLoader(getReactApplicationContext(), latestJSBundleFile, false);
        } else {
            latestJSBundleLoader = JSBundleLoader.createFileLoader(latestJSBundleFile);
        }

        Field bundleLoaderField = instanceManager.getClass().getDeclaredField("mBundleLoader");
        bundleLoaderField.setAccessible(true);
        bundleLoaderField.set(instanceManager, latestJSBundleLoader);
    } catch (Exception e) {
        throw new IllegalAccessException("Could not setJSBundle");
    }
}
 
Example 8
Project: react-native-threads   File: RNThreadModule.java   View source code 5 votes vote down vote up
@ReactMethod
public void startThread(final String jsFileName, final Promise promise) {
  Log.d(TAG, "Starting web thread - " + jsFileName);

  String jsFileSlug = jsFileName.contains("/") ? jsFileName.replaceAll("/", "_") : jsFileName;

  JSBundleLoader bundleLoader = getDevSupportManager().getDevSupportEnabled()
          ? createDevBundleLoader(jsFileName, jsFileSlug)
          : createReleaseBundleLoader(jsFileName, jsFileSlug);

  try {
    ArrayList<ReactPackage> threadPackages = new ArrayList<ReactPackage>(Arrays.asList(additionalThreadPackages));
    threadPackages.add(0, new ThreadBaseReactPackage(getReactInstanceManager()));

    ReactContextBuilder threadContextBuilder = new ReactContextBuilder(getReactApplicationContext())
            .setJSBundleLoader(bundleLoader)
            .setDevSupportManager(getDevSupportManager())
            .setReactInstanceManager(getReactInstanceManager())
            .setReactPackages(threadPackages);

    JSThread thread = new JSThread(jsFileSlug);
    thread.runFromContext(
            getReactApplicationContext(),
            threadContextBuilder
    );
    threads.put(thread.getThreadId(), thread);
    promise.resolve(thread.getThreadId());
  } catch (Exception e) {
    promise.reject(e);
    getDevSupportManager().handleException(e);
  }
}
 
Example 9
Project: react-native-threads   File: RNThreadModule.java   View source code 5 votes vote down vote up
private JSBundleLoader createDevBundleLoader(String jsFileName, String jsFileSlug) {
  String bundleUrl = bundleUrlForFile(jsFileName);
  String bundleOut = getReactApplicationContext().getFilesDir().getAbsolutePath() + "/" + jsFileSlug;

  Log.d(TAG, "createDevBundleLoader - download web thread to - " + bundleOut);
  downloadScriptToFileSync(bundleUrl, bundleOut);

  return JSBundleLoader.createCachedBundleFromNetworkLoader(bundleUrl, bundleOut);
}
 
Example 10
Project: ReactNativeSignatureExample   File: ReactInstanceManagerImpl.java   View source code 5 votes vote down vote up
private void onReloadWithJSDebugger(JavaJSExecutor.Factory jsExecutorFactory) {
  recreateReactContextInBackground(
      new ProxyJavaScriptExecutor.Factory(jsExecutorFactory),
      JSBundleLoader.createRemoteDebuggerBundleLoader(
          mDevSupportManager.getJSBundleURLForRemoteDebugging(),
          mDevSupportManager.getSourceUrl()));
}
 
Example 11
Project: ReactNativeSignatureExample   File: ReactInstanceManagerImpl.java   View source code 5 votes vote down vote up
private void onJSBundleLoadedFromServer() {
  recreateReactContextInBackground(
      new JSCJavaScriptExecutor.Factory(),
      JSBundleLoader.createCachedBundleFromNetworkLoader(
          mDevSupportManager.getSourceUrl(),
          mDevSupportManager.getDownloadedJSBundleFile()));
}
 
Example 12
Project: react-native-workers   File: WorkerModule.java   View source code 5 votes vote down vote up
@ReactMethod
public void startWorker(final String jsFileName, final Promise promise) {
    Log.d(TAG, "Starting web worker - " + jsFileName);

    String jsFileSlug = jsFileName.contains("/") ? jsFileName.replaceAll("/", "_") : jsFileName;

    JSBundleLoader bundleLoader = getDevSupportManager().getDevSupportEnabled()
            ? createDevBundleLoader(jsFileName, jsFileSlug)
            : createReleaseBundleLoader(jsFileName, jsFileSlug);

    try {
        ArrayList<ReactPackage> workerPackages = new ArrayList<ReactPackage>(Arrays.asList(additionalWorkerPackages));
        workerPackages.add(0, new BaseReactPackage(getReactInstanceManager()));

        ReactContextBuilder workerContextBuilder = new ReactContextBuilder(getReactApplicationContext())
                .setJSBundleLoader(bundleLoader)
                .setDevSupportManager(getDevSupportManager())
                .setReactPackages(workerPackages);

        JSWorker worker = new JSWorker(jsFileSlug);
        worker.runFromContext(
                getReactApplicationContext(),
                workerContextBuilder
        );
        workers.put(worker.getWorkerId(), worker);
        promise.resolve(worker.getWorkerId());
    } catch (Exception e) {
        promise.reject(e);
        getDevSupportManager().handleException(e);
    }
}
 
Example 13
Project: react-native-workers   File: WorkerModule.java   View source code 5 votes vote down vote up
private JSBundleLoader createDevBundleLoader(String jsFileName, String jsFileSlug) {
    String bundleUrl = bundleUrlForFile(jsFileName);
    String bundleOut = getReactApplicationContext().getFilesDir().getAbsolutePath() + "/" + jsFileSlug;

    Log.d(TAG, "createDevBundleLoader - download web worker to - " + bundleOut);
    downloadScriptToFileSync(bundleUrl, bundleOut);

    return JSBundleLoader.createCachedBundleFromNetworkLoader(bundleUrl, bundleOut);
}
 
Example 14
Project: react-native-ibeacon-android   File: ReactInstanceManagerImpl.java   View source code 5 votes vote down vote up
private void onReloadWithJSDebugger(JavaJSExecutor.Factory jsExecutorFactory) {
  recreateReactContextInBackground(
      new ProxyJavaScriptExecutor.Factory(jsExecutorFactory),
      JSBundleLoader.createRemoteDebuggerBundleLoader(
          mDevSupportManager.getJSBundleURLForRemoteDebugging(),
          mDevSupportManager.getSourceUrl()));
}
 
Example 15
Project: react-native-ibeacon-android   File: ReactInstanceManagerImpl.java   View source code 5 votes vote down vote up
private void onJSBundleLoadedFromServer() {
  recreateReactContextInBackground(
      new JSCJavaScriptExecutor.Factory(),
      JSBundleLoader.createCachedBundleFromNetworkLoader(
          mDevSupportManager.getSourceUrl(),
          mDevSupportManager.getDownloadedJSBundleFile()));
}
 
Example 16
Project: react-native-box-loaders   File: ReactInstanceManagerImpl.java   View source code 5 votes vote down vote up
private void onReloadWithJSDebugger(JavaJSExecutor.Factory jsExecutorFactory) {
  recreateReactContextInBackground(
      new ProxyJavaScriptExecutor.Factory(jsExecutorFactory),
      JSBundleLoader.createRemoteDebuggerBundleLoader(
          mDevSupportManager.getJSBundleURLForRemoteDebugging(),
          mDevSupportManager.getSourceUrl()));
}
 
Example 17
Project: react-native-box-loaders   File: ReactInstanceManagerImpl.java   View source code 5 votes vote down vote up
private void onJSBundleLoadedFromServer() {
  recreateReactContextInBackground(
      new JSCJavaScriptExecutor.Factory(),
      JSBundleLoader.createCachedBundleFromNetworkLoader(
          mDevSupportManager.getSourceUrl(),
          mDevSupportManager.getDownloadedJSBundleFile()));
}
 
Example 18
Project: react-native-threads   File: ReactContextBuilder.java   View source code 4 votes vote down vote up
public ReactContextBuilder setJSBundleLoader(JSBundleLoader jsBundleLoader) {
    this.jsBundleLoader = jsBundleLoader;
    return this;
}
 
Example 19
Project: react-native-threads   File: RNThreadModule.java   View source code 4 votes vote down vote up
private JSBundleLoader createReleaseBundleLoader(String jsFileName, String jsFileSlug) {
  Log.d(TAG, "createReleaseBundleLoader - reading file from assets");
  return JSBundleLoader.createAssetLoader(reactApplicationContext, "assets://threads/" + jsFileSlug + ".bundle", false);
}
 
Example 20
Project: ReactNativeSignatureExample   File: ReactInstanceManagerImpl.java   View source code 4 votes vote down vote up
public ReactContextInitParams(
    JavaScriptExecutor.Factory jsExecutorFactory,
    JSBundleLoader jsBundleLoader) {
  mJsExecutorFactory = Assertions.assertNotNull(jsExecutorFactory);
  mJsBundleLoader = Assertions.assertNotNull(jsBundleLoader);
}
 
Example 21
Project: ReactNativeSignatureExample   File: ReactInstanceManagerImpl.java   View source code 4 votes vote down vote up
public JSBundleLoader getJsBundleLoader() {
  return mJsBundleLoader;
}
 
Example 22
Project: ReactNativeSignatureExample   File: ReactInstanceManagerImpl.java   View source code 4 votes vote down vote up
private void recreateReactContextInBackgroundFromBundleFile() {
  recreateReactContextInBackground(
      new JSCJavaScriptExecutor.Factory(),
      JSBundleLoader.createFileLoader(mApplicationContext, mJSBundleFile));
}
 
Example 23
Project: react-native-workers   File: WorkerModule.java   View source code 4 votes vote down vote up
private JSBundleLoader createReleaseBundleLoader(String jsFileName, String jsFileSlug) {
    Log.d(TAG, "createReleaseBundleLoader - reading file from assets");
    return JSBundleLoader.createFileLoader(getReactApplicationContext(), "assets://workers/" + jsFileSlug + ".bundle");
}
 
Example 24
Project: react-native-workers   File: ReactContextBuilder.java   View source code 4 votes vote down vote up
public ReactContextBuilder setJSBundleLoader(JSBundleLoader jsBundleLoader) {
    this.jsBundleLoader = jsBundleLoader;
    return this;
}
 
Example 25
Project: react-native-ibeacon-android   File: ReactInstanceManagerImpl.java   View source code 4 votes vote down vote up
public ReactContextInitParams(
    JavaScriptExecutor.Factory jsExecutorFactory,
    JSBundleLoader jsBundleLoader) {
  mJsExecutorFactory = Assertions.assertNotNull(jsExecutorFactory);
  mJsBundleLoader = Assertions.assertNotNull(jsBundleLoader);
}
 
Example 26
Project: react-native-ibeacon-android   File: ReactInstanceManagerImpl.java   View source code 4 votes vote down vote up
public JSBundleLoader getJsBundleLoader() {
  return mJsBundleLoader;
}
 
Example 27
Project: react-native-ibeacon-android   File: ReactInstanceManagerImpl.java   View source code 4 votes vote down vote up
private void recreateReactContextInBackgroundFromBundleFile() {
  recreateReactContextInBackground(
      new JSCJavaScriptExecutor.Factory(),
      JSBundleLoader.createFileLoader(mApplicationContext, mJSBundleFile));
}
 
Example 28
Project: react-native-box-loaders   File: ReactInstanceManagerImpl.java   View source code 4 votes vote down vote up
public ReactContextInitParams(
    JavaScriptExecutor.Factory jsExecutorFactory,
    JSBundleLoader jsBundleLoader) {
  mJsExecutorFactory = Assertions.assertNotNull(jsExecutorFactory);
  mJsBundleLoader = Assertions.assertNotNull(jsBundleLoader);
}
 
Example 29
Project: react-native-box-loaders   File: ReactInstanceManagerImpl.java   View source code 4 votes vote down vote up
public JSBundleLoader getJsBundleLoader() {
  return mJsBundleLoader;
}
 
Example 30
Project: react-native-box-loaders   File: ReactInstanceManagerImpl.java   View source code 4 votes vote down vote up
private void recreateReactContextInBackgroundFromBundleFile() {
  recreateReactContextInBackground(
      new JSCJavaScriptExecutor.Factory(),
      JSBundleLoader.createFileLoader(mApplicationContext, mJSBundleFile));
}