diff --git a/Libraries/Core/Devtools/setupDevtools.js b/Libraries/Core/Devtools/setupDevtools.js index de1c9ec67e..c0fd77117f 100644 --- a/Libraries/Core/Devtools/setupDevtools.js +++ b/Libraries/Core/Devtools/setupDevtools.js @@ -11,30 +11,54 @@ */ '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'); const {PlatformConstants} = require('NativeModules'); - const {connectToDevTools} = require('react-devtools-core'); + const reactDevTools = require('react-devtools-core'); + + register = function (plugin: DevToolsPlugin) { + // 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'; - // Initialize dev tools only if the native module for WebSocket is available - if (WebSocket.isAvailable) { - connectToDevTools({ - isAppActive() { - // 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. - return AppState.currentState !== 'background'; - }, // Special case: Genymotion is running on a different host. - host: PlatformConstants && PlatformConstants.ServerHost ? + const host = PlatformConstants && PlatformConstants.ServerHost ? PlatformConstants.ServerHost.split(':')[0] : - 'localhost', - // 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'), - }); - } + 'localhost'; + + plugin.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'), + }); + } + }; + + register(reactDevTools); } + +module.exports = { + register, +};