-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate DevSettings related code to Kotlin (#43731)
Summary: Pull Request resolved: #43731 # Changelog: [Internal] - Converts code related to DevSettings Module/Activity to Kotlin. Reviewed By: cortinico Differential Revision: D55574529 fbshipit-source-id: 41057307d0a12685a937a232e02a1a7a15736abe
- Loading branch information
1 parent
88b6e11
commit a977b2e
Showing
7 changed files
with
211 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 0 additions & 137 deletions
137
...-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.java
This file was deleted.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
...ct-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
@file:Suppress("DEPRECATION") | ||
|
||
package com.facebook.react.devsupport | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener | ||
import android.preference.PreferenceManager | ||
import com.facebook.react.common.build.ReactBuildConfig | ||
import com.facebook.react.modules.debug.interfaces.DeveloperSettings | ||
import com.facebook.react.packagerconnection.PackagerConnectionSettings | ||
|
||
/** | ||
* Helper class for accessing developers settings that can not be accessed outside of the package | ||
* [com.facebook.react.devsupport]. For accessing some of the settings by external modules this | ||
* class implements an external interface [DeveloperSettings]. | ||
*/ | ||
internal class DevInternalSettings(applicationContext: Context, private val listener: Listener?) : | ||
DeveloperSettings, OnSharedPreferenceChangeListener { | ||
private val preferences: SharedPreferences = | ||
PreferenceManager.getDefaultSharedPreferences(applicationContext) | ||
val packagerConnectionSettings: PackagerConnectionSettings | ||
|
||
init { | ||
preferences.registerOnSharedPreferenceChangeListener(this) | ||
packagerConnectionSettings = PackagerConnectionSettings(applicationContext) | ||
} | ||
|
||
override fun isFpsDebugEnabled(): Boolean = preferences.getBoolean(PREFS_FPS_DEBUG_KEY, false) | ||
|
||
override fun isAnimationFpsDebugEnabled(): Boolean = | ||
preferences.getBoolean(PREFS_ANIMATIONS_DEBUG_KEY, false) | ||
|
||
override fun isJSDevModeEnabled(): Boolean = | ||
preferences.getBoolean(PREFS_JS_DEV_MODE_DEBUG_KEY, true) | ||
|
||
override fun isJSMinifyEnabled(): Boolean = | ||
preferences.getBoolean(PREFS_JS_MINIFY_DEBUG_KEY, false) | ||
|
||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String?) { | ||
if (listener != null) { | ||
if (PREFS_FPS_DEBUG_KEY == key || | ||
PREFS_JS_DEV_MODE_DEBUG_KEY == key || | ||
PREFS_START_SAMPLING_PROFILER_ON_INIT == key || | ||
PREFS_JS_MINIFY_DEBUG_KEY == key) { | ||
listener.onInternalSettingsChanged() | ||
} | ||
} | ||
} | ||
|
||
override fun isElementInspectorEnabled(): Boolean = | ||
preferences.getBoolean(PREFS_INSPECTOR_DEBUG_KEY, false) | ||
|
||
override fun isDeviceDebugEnabled(): Boolean = ReactBuildConfig.DEBUG | ||
|
||
override fun isRemoteJSDebugEnabled(): Boolean = | ||
preferences.getBoolean(PREFS_REMOTE_JS_DEBUG_KEY, false) | ||
|
||
override fun setRemoteJSDebugEnabled(remoteJSDebugEnabled: Boolean) { | ||
preferences.edit().putBoolean(PREFS_REMOTE_JS_DEBUG_KEY, remoteJSDebugEnabled).apply() | ||
} | ||
|
||
override fun isStartSamplingProfilerOnInit(): Boolean = | ||
preferences.getBoolean(PREFS_START_SAMPLING_PROFILER_ON_INIT, false) | ||
|
||
// Not supported. | ||
override fun addMenuItem(title: String) = Unit | ||
|
||
fun setElementInspectorEnabled(enabled: Boolean) { | ||
preferences.edit().putBoolean(PREFS_INSPECTOR_DEBUG_KEY, enabled).apply() | ||
} | ||
|
||
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() | ||
} | ||
|
||
companion object { | ||
private const val PREFS_FPS_DEBUG_KEY = "fps_debug" | ||
private const val PREFS_JS_DEV_MODE_DEBUG_KEY = "js_dev_mode_debug" | ||
private const val PREFS_JS_MINIFY_DEBUG_KEY = "js_minify_debug" | ||
private const val PREFS_ANIMATIONS_DEBUG_KEY = "animations_debug" | ||
private const val PREFS_INSPECTOR_DEBUG_KEY = "inspector_debug" | ||
private const val PREFS_HOT_MODULE_REPLACEMENT_KEY = "hot_module_replacement" | ||
private const val PREFS_REMOTE_JS_DEBUG_KEY = "remote_js_debug" | ||
private const val PREFS_START_SAMPLING_PROFILER_ON_INIT = "start_sampling_profiler_on_init" | ||
} | ||
} |
28 changes: 0 additions & 28 deletions
28
...-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSettingsActivity.java
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
...ct-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSettingsActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
@file:Suppress("DEPRECATION") | ||
|
||
package com.facebook.react.devsupport | ||
|
||
import android.os.Bundle | ||
import android.preference.PreferenceActivity | ||
import com.facebook.react.R | ||
|
||
/** | ||
* Activity that display developers settings. Should be added to the debug manifest of the app. Can | ||
* be triggered through the developers option menu displayed by [DevSupportManager]. | ||
*/ | ||
public class DevSettingsActivity : PreferenceActivity() { | ||
public override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
title = application.resources.getString(R.string.catalyst_settings_title) | ||
addPreferencesFromResource(R.xml.rn_dev_preferences) | ||
} | ||
} |
Oops, something went wrong.