mirror of
https://github.com/status-im/react-native.git
synced 2025-01-09 17:15:54 +00:00
1490ab12ef
Summary: Includes React Native and its dependencies Fresco, Metro, and Yoga. Excludes samples/examples/docs. find: ^(?:( *)|( *(?:[\*~#]|::))( )? *)?Copyright (?:\(c\) )?(\d{4})\b.+Facebook[\s\S]+?BSD[\s\S]+?(?:this source tree|the same directory)\.$ replace: $1$2$3Copyright (c) $4-present, Facebook, Inc.\n$2\n$1$2$3This source code is licensed under the MIT license found in the\n$1$2$3LICENSE file in the root directory of this source tree. Reviewed By: TheSavior, yungsters Differential Revision: D7007050 fbshipit-source-id: 37dd6bf0ffec0923bfc99c260bb330683f35553e
63 lines
1.9 KiB
JavaScript
63 lines
1.9 KiB
JavaScript
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @providesModule setupDevtools
|
|
* @flow
|
|
*/
|
|
'use strict';
|
|
|
|
type DevToolsPluginConnection = {
|
|
isAppActive: () => boolean,
|
|
host: string,
|
|
port: number,
|
|
};
|
|
|
|
type DevToolsPlugin = {
|
|
connectToDevTools: (connection: DevToolsPluginConnection) => void,
|
|
};
|
|
|
|
let register = function () {
|
|
// noop
|
|
};
|
|
|
|
if (__DEV__) {
|
|
const AppState = require('AppState');
|
|
const WebSocket = require('WebSocket');
|
|
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an
|
|
* error found when Flow v0.54 was deployed. To see the error delete this
|
|
* comment and run Flow. */
|
|
const reactDevTools = require('react-devtools-core');
|
|
const getDevServer = require('getDevServer');
|
|
|
|
// Initialize dev tools only if the native module for WebSocket is available
|
|
if (WebSocket.isAvailable) {
|
|
// Don't steal the DevTools from currently active app.
|
|
// Note: if you add any AppState subscriptions to this file,
|
|
// you will also need to guard against `AppState.isAvailable`,
|
|
// or the code will throw for bundles that don't have it.
|
|
const isAppActive = () => AppState.currentState !== 'background';
|
|
|
|
// Get hostname from development server (packager)
|
|
const devServer = getDevServer();
|
|
const host = devServer.bundleLoadedFromServer
|
|
? devServer.url.replace(/https?:\/\//, '').split(':')[0]
|
|
: 'localhost';
|
|
|
|
reactDevTools.connectToDevTools({
|
|
isAppActive,
|
|
host,
|
|
// Read the optional global variable for backward compatibility.
|
|
// It was added in https://github.com/facebook/react-native/commit/bf2b435322e89d0aeee8792b1c6e04656c2719a0.
|
|
port: window.__REACT_DEVTOOLS_PORT__,
|
|
resolveRNStyle: require('flattenStyle'),
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
register,
|
|
};
|