Java Code Examples for com.facebook.react.devsupport.interfaces.DevSupportManager#addCustomDevOption()

The following examples show how to use com.facebook.react.devsupport.interfaces.DevSupportManager#addCustomDevOption() . 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 File: MainActivity.java    From react-native-android-activity with MIT License 7 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 2
Source File: RNDevMenuModule.java    From react-native-dev-menu with 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);
  }
}