Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple DevInternalSettings from DevSupportManagerBase #44441

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -2085,8 +2085,7 @@ public abstract class com/facebook/react/devsupport/DevSupportManagerBase : com/
protected fun getCurrentContext ()Lcom/facebook/react/bridge/ReactContext;
public fun getDevLoadingViewManager ()Lcom/facebook/react/devsupport/interfaces/DevLoadingViewManager;
public fun getDevServerHelper ()Lcom/facebook/react/devsupport/DevServerHelper;
public fun getDevSettings ()Lcom/facebook/react/devsupport/DevInternalSettings;
public synthetic fun getDevSettings ()Lcom/facebook/react/modules/debug/interfaces/DeveloperSettings;
public fun getDevSettings ()Lcom/facebook/react/modules/debug/interfaces/DeveloperSettings;
public fun getDevSupportEnabled ()Z
public fun getDownloadedJSBundleFile ()Ljava/lang/String;
public fun getJSAppBundleName ()Ljava/lang/String;
Expand Down Expand Up @@ -2220,8 +2219,7 @@ public class com/facebook/react/devsupport/PackagerStatusCheck {

public final class com/facebook/react/devsupport/PerftestDevSupportManager : com/facebook/react/devsupport/ReleaseDevSupportManager {
public fun <init> (Landroid/content/Context;)V
public fun getDevSettings ()Lcom/facebook/react/devsupport/DevInternalSettings;
public synthetic fun getDevSettings ()Lcom/facebook/react/modules/debug/interfaces/DeveloperSettings;
public fun getDevSettings ()Lcom/facebook/react/modules/debug/interfaces/DeveloperSettings;
public fun startInspector ()V
public fun stopInspector ()V
}
Expand Down Expand Up @@ -3227,15 +3225,25 @@ public class com/facebook/react/modules/debug/SourceCodeModule : com/facebook/fb

public abstract interface class com/facebook/react/modules/debug/interfaces/DeveloperSettings {
public abstract fun addMenuItem (Ljava/lang/String;)V
public abstract fun getPackagerConnectionSettings ()Lcom/facebook/react/packagerconnection/PackagerConnectionSettings;
public abstract fun isAnimationFpsDebugEnabled ()Z
public abstract fun isDeviceDebugEnabled ()Z
public abstract fun isElementInspectorEnabled ()Z
public abstract fun isFpsDebugEnabled ()Z
public abstract fun isHotModuleReplacementEnabled ()Z
public abstract fun isJSDevModeEnabled ()Z
public abstract fun isJSMinifyEnabled ()Z
public abstract fun isRemoteJSDebugEnabled ()Z
public abstract fun isStartSamplingProfilerOnInit ()Z
public abstract fun setAnimationFpsDebugEnabled (Z)V
public abstract fun setDeviceDebugEnabled (Z)V
public abstract fun setElementInspectorEnabled (Z)V
public abstract fun setFpsDebugEnabled (Z)V
public abstract fun setHotModuleReplacementEnabled (Z)V
public abstract fun setJSDevModeEnabled (Z)V
public abstract fun setJSMinifyEnabled (Z)V
public abstract fun setRemoteJSDebugEnabled (Z)V
public abstract fun setStartSamplingProfilerOnInit (Z)V
}

public class com/facebook/react/modules/deviceinfo/DeviceInfoModule : com/facebook/fbreact/specs/NativeDeviceInfoSpec, com/facebook/react/bridge/LifecycleEventListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,36 @@ internal class DevInternalSettings(applicationContext: Context, private val list
DeveloperSettings, OnSharedPreferenceChangeListener {
private val preferences: SharedPreferences =
PreferenceManager.getDefaultSharedPreferences(applicationContext)
val packagerConnectionSettings: PackagerConnectionSettings
override val packagerConnectionSettings: PackagerConnectionSettings =
PackagerConnectionSettings(applicationContext)

init {
preferences.registerOnSharedPreferenceChangeListener(this)
packagerConnectionSettings = PackagerConnectionSettings(applicationContext)
}

override fun isFpsDebugEnabled(): Boolean = preferences.getBoolean(PREFS_FPS_DEBUG_KEY, false)
override var isFpsDebugEnabled: Boolean
get() = preferences.getBoolean(PREFS_FPS_DEBUG_KEY, false)
set(value) {
preferences.edit().putBoolean(PREFS_FPS_DEBUG_KEY, value).apply()
}

override fun isAnimationFpsDebugEnabled(): Boolean =
preferences.getBoolean(PREFS_ANIMATIONS_DEBUG_KEY, false)
override var isAnimationFpsDebugEnabled: Boolean
get() = preferences.getBoolean(PREFS_ANIMATIONS_DEBUG_KEY, false)
set(_) {
// not used
}

override fun isJSDevModeEnabled(): Boolean =
preferences.getBoolean(PREFS_JS_DEV_MODE_DEBUG_KEY, true)
override var isJSDevModeEnabled: Boolean
get() = preferences.getBoolean(PREFS_JS_DEV_MODE_DEBUG_KEY, true)
set(value) {
preferences.edit().putBoolean(PREFS_JS_DEV_MODE_DEBUG_KEY, value).apply()
}

override fun isJSMinifyEnabled(): Boolean =
preferences.getBoolean(PREFS_JS_MINIFY_DEBUG_KEY, false)
override var isJSMinifyEnabled: Boolean
get() = preferences.getBoolean(PREFS_JS_MINIFY_DEBUG_KEY, false)
set(_) {
// not used
}

override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String?) {
if (listener != null) {
Expand All @@ -55,42 +68,35 @@ internal class DevInternalSettings(applicationContext: Context, private val list
}
}

override fun isElementInspectorEnabled(): Boolean =
preferences.getBoolean(PREFS_INSPECTOR_DEBUG_KEY, false)

override fun isDeviceDebugEnabled(): Boolean = ReactBuildConfig.DEBUG
override var isElementInspectorEnabled: Boolean
get() = preferences.getBoolean(PREFS_INSPECTOR_DEBUG_KEY, false)
set(value) {
preferences.edit().putBoolean(PREFS_INSPECTOR_DEBUG_KEY, value).apply()
}

override fun isRemoteJSDebugEnabled(): Boolean =
preferences.getBoolean(PREFS_REMOTE_JS_DEBUG_KEY, false)
override var isDeviceDebugEnabled: Boolean = ReactBuildConfig.DEBUG

override fun setRemoteJSDebugEnabled(remoteJSDebugEnabled: Boolean) {
preferences.edit().putBoolean(PREFS_REMOTE_JS_DEBUG_KEY, remoteJSDebugEnabled).apply()
}
override var isRemoteJSDebugEnabled: Boolean
get() = preferences.getBoolean(PREFS_REMOTE_JS_DEBUG_KEY, false)
set(value) {
preferences.edit().putBoolean(PREFS_REMOTE_JS_DEBUG_KEY, value).apply()
}

override fun isStartSamplingProfilerOnInit(): Boolean =
preferences.getBoolean(PREFS_START_SAMPLING_PROFILER_ON_INIT, false)
override var isStartSamplingProfilerOnInit: Boolean
get() = preferences.getBoolean(PREFS_START_SAMPLING_PROFILER_ON_INIT, false)
set(_) {
// not used
}

// Not supported.
override fun addMenuItem(title: String) = Unit

fun setElementInspectorEnabled(enabled: Boolean) {
preferences.edit().putBoolean(PREFS_INSPECTOR_DEBUG_KEY, enabled).apply()
}

var isHotModuleReplacementEnabled: Boolean
override var isHotModuleReplacementEnabled: Boolean
get() = preferences.getBoolean(PREFS_HOT_MODULE_REPLACEMENT_KEY, true)
set(enabled) {
preferences.edit().putBoolean(PREFS_HOT_MODULE_REPLACEMENT_KEY, enabled).apply()
}

fun setJSDevModeEnabled(value: Boolean) {
preferences.edit().putBoolean(PREFS_JS_DEV_MODE_DEBUG_KEY, value).apply()
}

fun setFpsDebugEnabled(enabled: Boolean) {
preferences.edit().putBoolean(PREFS_FPS_DEBUG_KEY, enabled).apply()
}

interface Listener {
fun onInternalSettingsChanged()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
import com.facebook.react.devsupport.interfaces.StackFrame;
import com.facebook.react.modules.core.RCTNativeAppEventEmitter;
import com.facebook.react.modules.debug.interfaces.DeveloperSettings;
import com.facebook.react.packagerconnection.RequestHandler;
import com.facebook.react.packagerconnection.Responder;
import java.io.File;
Expand Down Expand Up @@ -107,7 +108,7 @@ public interface CallbackWithBundleLoader {
private boolean mDevLoadingViewVisible = false;
private int mPendingJSSplitBundleRequests = 0;
private @Nullable ReactContext mCurrentContext;
private final DevInternalSettings mDevSettings;
private final DeveloperSettings mDevSettings;
private boolean mIsReceiverRegistered = false;
private boolean mIsShakeDetectorStarted = false;
private boolean mIsDevSupportEnabled = false;
Expand Down Expand Up @@ -593,7 +594,7 @@ public boolean getDevSupportEnabled() {
}

@Override
public DevInternalSettings getDevSettings() {
public DeveloperSettings getDevSettings() {
return mDevSettings;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import android.content.Context;
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.react.modules.debug.interfaces.DeveloperSettings;

/**
* Interface for accessing and interacting with development features related to performance testing.
Expand All @@ -17,7 +18,7 @@
@Nullsafe(Nullsafe.Mode.LOCAL)
public final class PerftestDevSupportManager extends ReleaseDevSupportManager {
private final DevServerHelper mDevServerHelper;
private final DevInternalSettings mDevSettings;
private final DeveloperSettings mDevSettings;

public PerftestDevSupportManager(Context applicationContext) {
mDevSettings =
Expand All @@ -35,7 +36,7 @@ public void onInternalSettingsChanged() {}
}

@Override
public DevInternalSettings getDevSettings() {
public DeveloperSettings getDevSettings() {
return mDevSettings;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,39 @@

package com.facebook.react.modules.debug.interfaces

import com.facebook.react.packagerconnection.PackagerConnectionSettings

/** Provides access to React Native developers settings. */
public interface DeveloperSettings {
/** Return the underlying [PackagerConnectionSettings] instance. */
public val packagerConnectionSettings: PackagerConnectionSettings

/** whether an overlay showing current FPS should be shown. */
public fun isFpsDebugEnabled(): Boolean
/** Whether an overlay showing current FPS should be shown. */
public var isFpsDebugEnabled: Boolean
Comment on lines -13 to +18
Copy link
Contributor

Choose a reason for hiding this comment

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

@Kudo This question applies to all fun -> var changes, but it appears as you are taking a read-only interface and making it read-write for everyone. Is this a safe change to make?
Also if the internal visibility DevInternalSettings is of an issue, would it be just better to make it public?


/** Whether debug information about transitions should be displayed. */
public fun isAnimationFpsDebugEnabled(): Boolean
public var isAnimationFpsDebugEnabled: Boolean

/** Whether dev mode should be enabled in JS bundles. */
public fun isJSDevModeEnabled(): Boolean
public var isJSDevModeEnabled: Boolean

/** Whether JS bundle should be minified. */
public fun isJSMinifyEnabled(): Boolean
public var isJSMinifyEnabled: Boolean

/** Whether element inspector is enabled. */
public fun isElementInspectorEnabled(): Boolean
public var isElementInspectorEnabled: Boolean

/** Whether Nuclide JS debugging is enabled. */
public fun isDeviceDebugEnabled(): Boolean
public var isDeviceDebugEnabled: Boolean

/** Whether remote JS debugging is enabled. */
public fun isRemoteJSDebugEnabled(): Boolean

/** Enable/Disable remote JS debugging. */
public fun setRemoteJSDebugEnabled(remoteJSDebugEnabled: Boolean)
public var isRemoteJSDebugEnabled: Boolean

/** Whether Start Sampling Profiler on App Start is enabled. */
public fun isStartSamplingProfilerOnInit(): Boolean
public var isStartSamplingProfilerOnInit: Boolean

/** Whether HMR is enabled. */
public var isHotModuleReplacementEnabled: Boolean

/** Add an item to the dev menu. */
public fun addMenuItem(title: String)
Expand Down