Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions ReactAndroid/src/main/java/com/facebook/react/Experiments.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

package com.facebook.react;

import java.util.HashSet;
import java.util.Set;


/**
* This class exposes a way to enable/disable experimental features in React Native.
*/
public class Experiments {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Javadoc explaining what the reason this class exist is please.


// Enables Hot Module Replacement menu item in the developer menu
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

public static String HOT_MODULE_REPLACEMENT = "HOT_MODULE_REPLACEMENT";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Javadoc with a short explanation this shows/hides the HMR menu please.


private static Set<String> enabledExperiments;

/**
* Enables an experiment
*/
public static void enableExperiment(String experiment) {
if (enabledExperiments == null) {
enabledExperiments = new HashSet<>();
}
enabledExperiments.add(experiment);
}

/**
* Disables an experiment
*/
public static void disableExperiment(String experiment) {
if (enabledExperiments != null) {
enabledExperiments.remove(experiment);
}
}

/**
* Checks if an experiment is enabled
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a matter of personal preference but these three methods have so clear names they probably don't require Javadoc. If you prefer keep it but please remove the @param experiment - these don't add meaning to what's already in the code.

public static boolean isExperimentEnabled(String experiment) {
return enabledExperiments != null && enabledExperiments.contains(experiment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.Experiments;
import com.facebook.react.R;
import com.facebook.react.bridge.CatalystInstance;
import com.facebook.react.bridge.DefaultNativeModuleCallExceptionHandler;
Expand Down Expand Up @@ -265,17 +266,21 @@ public void onOptionSelected() {
handleReloadJS();
}
});
options.put(
mDevSettings.isHotModuleReplacementEnabled()
? mApplicationContext.getString(R.string.catalyst_hot_module_replacement_off)
: mApplicationContext.getString(R.string.catalyst_hot_module_replacement),
new DevOptionHandler() {
@Override
public void onOptionSelected() {
mDevSettings.setHotModuleReplacementEnabled(!mDevSettings.isHotModuleReplacementEnabled());
handleReloadJS();
}
});

if (Experiments.isExperimentEnabled(Experiments.HOT_MODULE_REPLACEMENT)) {
options.put(
mDevSettings.isHotModuleReplacementEnabled()
? mApplicationContext.getString(R.string.catalyst_hot_module_replacement_off)
: mApplicationContext.getString(R.string.catalyst_hot_module_replacement),
new DevOptionHandler() {
@Override
public void onOptionSelected() {
mDevSettings.setHotModuleReplacementEnabled(!mDevSettings.isHotModuleReplacementEnabled());
handleReloadJS();
}
});
}

options.put(
mDevSettings.isReloadOnJSChangeEnabled()
? mApplicationContext.getString(R.string.catalyst_live_reload_off)
Expand Down