Java Code Examples for com.facebook.react.devsupport.interfaces.DevSupportManager

The following examples show how to use com.facebook.react.devsupport.interfaces.DevSupportManager. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: react-native-GPay   Source File: Timing.java    License: MIT License 6 votes vote down vote up
public Timing(ReactApplicationContext reactContext, DevSupportManager devSupportManager) {
  super(reactContext);
  mDevSupportManager = devSupportManager;
  // We store timers sorted by finish time.
  mTimers = new PriorityQueue<Timer>(
      11, // Default capacity: for some reason they don't expose a (Comparator) constructor
      new Comparator<Timer>() {
        @Override
        public int compare(Timer lhs, Timer rhs) {
          long diff = lhs.mTargetTime - rhs.mTargetTime;
          if (diff == 0) {
            return 0;
          } else if (diff < 0) {
            return -1;
          } else {
            return 1;
          }
        }
      });
  mTimerIdsToTimers = new SparseArray<>();
  mReactChoreographer = ReactChoreographer.getInstance();
}
 
Example 2
Source Project: react-native-GPay   Source File: DevSupportManagerFactory.java    License: MIT License 6 votes vote down vote up
public static DevSupportManager create(
    Context applicationContext,
    ReactInstanceManagerDevHelper reactInstanceManagerHelper,
    @Nullable String packagerPathForJSBundleName,
    boolean enableOnCreate,
    int minNumShakes) {

  return create(
    applicationContext,
    reactInstanceManagerHelper,
    packagerPathForJSBundleName,
    enableOnCreate,
    null,
    null,
    minNumShakes,
    null);
}
 
Example 3
Source Project: react-native-GPay   Source File: ReactIntegrationTestCase.java    License: MIT License 6 votes vote down vote up
/**
 * Timing module needs to be created on the main thread so that it gets the correct Choreographer.
 */
protected Timing createTimingModule() {
  final SimpleSettableFuture<Timing> simpleSettableFuture = new SimpleSettableFuture<Timing>();
  UiThreadUtil.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          ReactChoreographer.initialize();
          Timing timing = new Timing(getContext(), mock(DevSupportManager.class));
          simpleSettableFuture.set(timing);
        }
      });
  try {
    return simpleSettableFuture.get(5000, TimeUnit.MILLISECONDS);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 4
Source Project: react-native-android-activity   Source File: MainActivity.java    License: MIT License 6 votes vote down vote up
/**
 * Demonstrates how to add a custom option to the dev menu.
 * https://stackoverflow.com/a/44882371/3968276
 * This only works from the debug build with dev options enabled.
 */
@Override
@CallSuper
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    MainApplication application = (MainApplication) getApplication();
    ReactNativeHost reactNativeHost = application.getReactNativeHost();
    ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
    DevSupportManager devSupportManager = reactInstanceManager.getDevSupportManager();
    devSupportManager.addCustomDevOption("Custom dev option", new DevOptionHandler() {
        @Override
        public void onOptionSelected() {
            if (NotificationManagerCompat.from(MainActivity.this).areNotificationsEnabled()) {
                Toast.makeText(MainActivity.this, CUSTOM_DEV_OPTION_MESSAGE, Toast.LENGTH_LONG).show();
            } else {
                AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).create();
                dialog.setTitle("Dev option");
                dialog.setMessage(CUSTOM_DEV_OPTION_MESSAGE);
                dialog.show();
            }
        }
    });
}
 
Example 5
Source Project: react-native-dev-menu   Source File: RNDevMenuModule.java    License: MIT License 5 votes vote down vote up
@ReactMethod
public void addItem(final String name, Promise promise) {
  if (mNames == null) {
    mNames = new ArrayList<>();
  }
  if (mNames.contains(name)) {
    promise.resolve(null);
  }

  try {
    ReactApplication application = (ReactApplication)getReactApplicationContext()
      .getCurrentActivity()
      .getApplication();

    DevSupportManager manager = application
      .getReactNativeHost()
      .getReactInstanceManager()
      .getDevSupportManager();

    manager.addCustomDevOption(name, new DevOptionHandler() {
      @Override
      public void onOptionSelected() {
        getReactApplicationContext().getJSModule(RCTDeviceEventEmitter.class)
                .emit("customDevOptionTap", name);
      }
    });

    mNames.add(name);
    promise.resolve(null);
  } catch (Exception e) {
    promise.reject(e);
  }
}
 
Example 6
Source Project: react-native-GPay   Source File: ExceptionsManagerModule.java    License: MIT License 4 votes vote down vote up
public ExceptionsManagerModule(DevSupportManager devSupportManager) {
  mDevSupportManager = devSupportManager;
}
 
Example 7
Source Project: react-native-GPay   Source File: ReactInstanceManager.java    License: MIT License 4 votes vote down vote up
public DevSupportManager getDevSupportManager() {
  return mDevSupportManager;
}
 
Example 8
Source Project: react-native-GPay   Source File: DevSupportManagerFactory.java    License: MIT License 4 votes vote down vote up
public static DevSupportManager create(
  Context applicationContext,
  ReactInstanceManagerDevHelper reactInstanceManagerHelper,
  @Nullable String packagerPathForJSBundleName,
  boolean enableOnCreate,
  @Nullable RedBoxHandler redBoxHandler,
  @Nullable DevBundleDownloadListener devBundleDownloadListener,
  int minNumShakes,
  @Nullable Map<String, RequestHandler> customPackagerCommandHandlers) {
  if (!enableOnCreate) {
    return new DisabledDevSupportManager();
  }
  try {
    // ProGuard is surprisingly smart in this case and will keep a class if it detects a call to
    // Class.forName() with a static string. So instead we generate a quasi-dynamic string to
    // confuse it.
    String className =
      new StringBuilder(DEVSUPPORT_IMPL_PACKAGE)
        .append(".")
        .append(DEVSUPPORT_IMPL_CLASS)
        .toString();
    Class<?> devSupportManagerClass =
      Class.forName(className);
    Constructor constructor =
      devSupportManagerClass.getConstructor(
        Context.class,
        ReactInstanceManagerDevHelper.class,
        String.class,
        boolean.class,
        RedBoxHandler.class,
        DevBundleDownloadListener.class,
        int.class,
        Map.class);
    return (DevSupportManager) constructor.newInstance(
      applicationContext,
      reactInstanceManagerHelper,
      packagerPathForJSBundleName,
      true,
      redBoxHandler,
      devBundleDownloadListener,
      minNumShakes,
      customPackagerCommandHandlers);
  } catch (Exception e) {
    throw new RuntimeException(
      "Requested enabled DevSupportManager, but DevSupportManagerImpl class was not found" +
        " or could not be created",
      e);
  }
}
 
Example 9
Source Project: react-native-GPay   Source File: RedBoxDialog.java    License: MIT License 4 votes vote down vote up
private OpenStackFrameTask(DevSupportManager devSupportManager) {
  mDevSupportManager = devSupportManager;
}
 
Example 10
Source Project: react-native-GPay   Source File: RedBoxDialog.java    License: MIT License 4 votes vote down vote up
private CopyToHostClipBoardTask(DevSupportManager devSupportManager) {
  mDevSupportManager = devSupportManager;
}
 
Example 11
Source Project: react-native-threads   Source File: ReactContextBuilder.java    License: MIT License 4 votes vote down vote up
public ReactContextBuilder setDevSupportManager(DevSupportManager devSupportManager) {
    this.devSupportManager = devSupportManager;
    return this;
}
 
Example 12
Source Project: react-native-threads   Source File: RNThreadModule.java    License: MIT License 4 votes vote down vote up
private DevSupportManager getDevSupportManager() {
  return getReactInstanceManager().getDevSupportManager();
}
 
Example 13
Source Project: react-native-navigation   Source File: JsDevReloadHandler.java    License: MIT License 4 votes vote down vote up
JsDevReloadHandler(DevSupportManager devSupportManager) {
    this.devSupportManager = devSupportManager;
}