forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
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 (facebook#43731)
Summary: Pull Request resolved: facebook#43731 # Changelog: [Internal] - Converts code related to DevSettings Module/Activity to Kotlin. Differential Revision: D55574529
- Loading branch information
1 parent
2ba07df
commit ea72528
Showing
7 changed files
with
213 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.
112 changes: 112 additions & 0 deletions
112
...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,112 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
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 { | ||
return preferences.getBoolean(PREFS_INSPECTOR_DEBUG_KEY, false) | ||
} | ||
|
||
override fun isDeviceDebugEnabled(): Boolean { | ||
return ReactBuildConfig.DEBUG | ||
} | ||
|
||
override fun isRemoteJSDebugEnabled(): Boolean { | ||
return 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 { | ||
return preferences.getBoolean(PREFS_START_SAMPLING_PROFILER_ON_INIT, false) | ||
} | ||
|
||
override fun addMenuItem(title: String) { | ||
// Not supported. | ||
} | ||
|
||
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.
24 changes: 24 additions & 0 deletions
24
...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,24 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
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.