mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Use native module to persist RDT settings (#46663)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46663 # Changelog: [Internal] Now we can use the native module for persisting settings in React DevTools. Basically, this diff adds read / write implementations. Reviewed By: huntie Differential Revision: D62967060 fbshipit-source-id: c14ef056c8d7e30a23d2b84d1ad4fc0ad8eaaf34
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d336a7c9c6
commit
459fadce77
+24
-1
@@ -21,8 +21,23 @@ if (__DEV__) {
|
||||
connectWithCustomMessagingProtocol,
|
||||
} = require('react-devtools-core');
|
||||
|
||||
const reactDevToolsSettingsManager = require('../../src/private/reactdevtools/ReactDevToolsSettingsManager');
|
||||
const serializedHookSettings =
|
||||
reactDevToolsSettingsManager.getGlobalHookSettings();
|
||||
|
||||
let hookSettings = null;
|
||||
if (serializedHookSettings != null) {
|
||||
try {
|
||||
const parsedSettings = JSON.parse(serializedHookSettings);
|
||||
hookSettings = parsedSettings;
|
||||
} catch {
|
||||
console.error(
|
||||
'Failed to parse persisted React DevTools hook settings. React DevTools will be initialized with default settings.',
|
||||
);
|
||||
}
|
||||
}
|
||||
// Install hook before React is loaded.
|
||||
initialize();
|
||||
initialize(hookSettings);
|
||||
|
||||
// This should be defined in DEV, otherwise error is expected.
|
||||
const fuseboxReactDevToolsDispatcher =
|
||||
@@ -33,6 +48,12 @@ if (__DEV__) {
|
||||
const ReactNativeStyleAttributes = require('../Components/View/ReactNativeStyleAttributes');
|
||||
const resolveRNStyle = require('../StyleSheet/flattenStyle');
|
||||
|
||||
function handleReactDevToolsSettingsUpdate(settings: Object) {
|
||||
reactDevToolsSettingsManager.setGlobalHookSettings(
|
||||
JSON.stringify(settings),
|
||||
);
|
||||
}
|
||||
|
||||
let disconnect = null;
|
||||
function disconnectBackendFromReactDevToolsInFuseboxIfNeeded() {
|
||||
if (disconnect != null) {
|
||||
@@ -54,6 +75,7 @@ if (__DEV__) {
|
||||
},
|
||||
nativeStyleEditorValidAttributes: Object.keys(ReactNativeStyleAttributes),
|
||||
resolveRNStyle,
|
||||
onSettingsUpdated: handleReactDevToolsSettingsUpdate,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -112,6 +134,7 @@ if (__DEV__) {
|
||||
ReactNativeStyleAttributes,
|
||||
),
|
||||
websocket: ws,
|
||||
onSettingsUpdated: handleReactDevToolsSettingsUpdate,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user