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

The following examples show how to use com.facebook.react.devsupport.interfaces.DevOptionHandler. 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-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 2
Source Project: react-native-GPay   Source File: DevSupportManagerImpl.java    License: MIT License 5 votes vote down vote up
/**
 * Add option item to dev settings dialog displayed by this manager. In the case user select given
 * option from that dialog, the appropriate handler passed as {@param optionHandler} will be
 * called.
 */
@Override
public void addCustomDevOption(
    String optionName,
    DevOptionHandler optionHandler) {
  mCustomDevOptions.put(optionName, optionHandler);
}
 
Example 3
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 4
Source Project: react-native-GPay   Source File: DisabledDevSupportManager.java    License: MIT License 2 votes vote down vote up
@Override
public void addCustomDevOption(String optionName, DevOptionHandler optionHandler) {

}