Java 类com.facebook.react.bridge.JSBundleLoader 实例源码

项目:ReactNativeSignatureExample    文件:ReactInstanceManagerImpl.java   
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;
  }
}
项目:ReactNativeSignatureExample    文件:ReactTestHelper.java   
@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();
}
项目:react-native-ibeacon-android    文件:ReactInstanceManagerImpl.java   
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;
  }
}
项目:react-native-ibeacon-android    文件:ReactTestHelper.java   
@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();
}
项目:react-native-box-loaders    文件:ReactInstanceManagerImpl.java   
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;
  }
}
项目:react-native-box-loaders    文件:ReactTestHelper.java   
@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();
}
项目:react-native-update    文件:RCTUpdate.java   
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");
    }
}
项目:react-native-threads    文件:RNThreadModule.java   
@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);
  }
}
项目:react-native-threads    文件:RNThreadModule.java   
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);
}
项目:ReactNativeSignatureExample    文件:ReactInstanceManagerImpl.java   
private void onReloadWithJSDebugger(JavaJSExecutor.Factory jsExecutorFactory) {
  recreateReactContextInBackground(
      new ProxyJavaScriptExecutor.Factory(jsExecutorFactory),
      JSBundleLoader.createRemoteDebuggerBundleLoader(
          mDevSupportManager.getJSBundleURLForRemoteDebugging(),
          mDevSupportManager.getSourceUrl()));
}
项目:ReactNativeSignatureExample    文件:ReactInstanceManagerImpl.java   
private void onJSBundleLoadedFromServer() {
  recreateReactContextInBackground(
      new JSCJavaScriptExecutor.Factory(),
      JSBundleLoader.createCachedBundleFromNetworkLoader(
          mDevSupportManager.getSourceUrl(),
          mDevSupportManager.getDownloadedJSBundleFile()));
}
项目:react-native-workers    文件:WorkerModule.java   
@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);
    }
}
项目:react-native-workers    文件:WorkerModule.java   
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);
}
项目:react-native-ibeacon-android    文件:ReactInstanceManagerImpl.java   
private void onReloadWithJSDebugger(JavaJSExecutor.Factory jsExecutorFactory) {
  recreateReactContextInBackground(
      new ProxyJavaScriptExecutor.Factory(jsExecutorFactory),
      JSBundleLoader.createRemoteDebuggerBundleLoader(
          mDevSupportManager.getJSBundleURLForRemoteDebugging(),
          mDevSupportManager.getSourceUrl()));
}
项目:react-native-ibeacon-android    文件:ReactInstanceManagerImpl.java   
private void onJSBundleLoadedFromServer() {
  recreateReactContextInBackground(
      new JSCJavaScriptExecutor.Factory(),
      JSBundleLoader.createCachedBundleFromNetworkLoader(
          mDevSupportManager.getSourceUrl(),
          mDevSupportManager.getDownloadedJSBundleFile()));
}
项目:react-native-box-loaders    文件:ReactInstanceManagerImpl.java   
private void onReloadWithJSDebugger(JavaJSExecutor.Factory jsExecutorFactory) {
  recreateReactContextInBackground(
      new ProxyJavaScriptExecutor.Factory(jsExecutorFactory),
      JSBundleLoader.createRemoteDebuggerBundleLoader(
          mDevSupportManager.getJSBundleURLForRemoteDebugging(),
          mDevSupportManager.getSourceUrl()));
}
项目:react-native-box-loaders    文件:ReactInstanceManagerImpl.java   
private void onJSBundleLoadedFromServer() {
  recreateReactContextInBackground(
      new JSCJavaScriptExecutor.Factory(),
      JSBundleLoader.createCachedBundleFromNetworkLoader(
          mDevSupportManager.getSourceUrl(),
          mDevSupportManager.getDownloadedJSBundleFile()));
}
项目:react-native-threads    文件:ReactContextBuilder.java   
public ReactContextBuilder setJSBundleLoader(JSBundleLoader jsBundleLoader) {
    this.jsBundleLoader = jsBundleLoader;
    return this;
}
项目:react-native-threads    文件:RNThreadModule.java   
private JSBundleLoader createReleaseBundleLoader(String jsFileName, String jsFileSlug) {
  Log.d(TAG, "createReleaseBundleLoader - reading file from assets");
  return JSBundleLoader.createAssetLoader(reactApplicationContext, "assets://threads/" + jsFileSlug + ".bundle", false);
}
项目:ReactNativeSignatureExample    文件:ReactInstanceManagerImpl.java   
public ReactContextInitParams(
    JavaScriptExecutor.Factory jsExecutorFactory,
    JSBundleLoader jsBundleLoader) {
  mJsExecutorFactory = Assertions.assertNotNull(jsExecutorFactory);
  mJsBundleLoader = Assertions.assertNotNull(jsBundleLoader);
}
项目:ReactNativeSignatureExample    文件:ReactInstanceManagerImpl.java   
public JSBundleLoader getJsBundleLoader() {
  return mJsBundleLoader;
}
项目:ReactNativeSignatureExample    文件:ReactInstanceManagerImpl.java   
private void recreateReactContextInBackgroundFromBundleFile() {
  recreateReactContextInBackground(
      new JSCJavaScriptExecutor.Factory(),
      JSBundleLoader.createFileLoader(mApplicationContext, mJSBundleFile));
}
项目:react-native-workers    文件:WorkerModule.java   
private JSBundleLoader createReleaseBundleLoader(String jsFileName, String jsFileSlug) {
    Log.d(TAG, "createReleaseBundleLoader - reading file from assets");
    return JSBundleLoader.createFileLoader(getReactApplicationContext(), "assets://workers/" + jsFileSlug + ".bundle");
}
项目:react-native-workers    文件:ReactContextBuilder.java   
public ReactContextBuilder setJSBundleLoader(JSBundleLoader jsBundleLoader) {
    this.jsBundleLoader = jsBundleLoader;
    return this;
}
项目:react-native-ibeacon-android    文件:ReactInstanceManagerImpl.java   
public ReactContextInitParams(
    JavaScriptExecutor.Factory jsExecutorFactory,
    JSBundleLoader jsBundleLoader) {
  mJsExecutorFactory = Assertions.assertNotNull(jsExecutorFactory);
  mJsBundleLoader = Assertions.assertNotNull(jsBundleLoader);
}
项目:react-native-ibeacon-android    文件:ReactInstanceManagerImpl.java   
public JSBundleLoader getJsBundleLoader() {
  return mJsBundleLoader;
}
项目:react-native-ibeacon-android    文件:ReactInstanceManagerImpl.java   
private void recreateReactContextInBackgroundFromBundleFile() {
  recreateReactContextInBackground(
      new JSCJavaScriptExecutor.Factory(),
      JSBundleLoader.createFileLoader(mApplicationContext, mJSBundleFile));
}
项目:react-native-box-loaders    文件:ReactInstanceManagerImpl.java   
public ReactContextInitParams(
    JavaScriptExecutor.Factory jsExecutorFactory,
    JSBundleLoader jsBundleLoader) {
  mJsExecutorFactory = Assertions.assertNotNull(jsExecutorFactory);
  mJsBundleLoader = Assertions.assertNotNull(jsBundleLoader);
}
项目:react-native-box-loaders    文件:ReactInstanceManagerImpl.java   
public JSBundleLoader getJsBundleLoader() {
  return mJsBundleLoader;
}
项目:react-native-box-loaders    文件:ReactInstanceManagerImpl.java   
private void recreateReactContextInBackgroundFromBundleFile() {
  recreateReactContextInBackground(
      new JSCJavaScriptExecutor.Factory(),
      JSBundleLoader.createFileLoader(mApplicationContext, mJSBundleFile));
}