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

The following examples show how to use com.facebook.react.devsupport.interfaces.DevOptionHandler. 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: DevSupportManagerImpl.java    From react-native-GPay with 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 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);
  }
}
 
Example #4
Source File: DisabledDevSupportManager.java    From react-native-GPay with MIT License 2 votes vote down vote up
@Override
public void addCustomDevOption(String optionName, DevOptionHandler optionHandler) {

}