mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-08 07:53:15 +08:00
Summary: `setupDevtools.js` is accessing `AppState.currentState` without checking its availability. In environments where 1) `__DEV__ == true`, and 2) no `RCTAppState` native module is provided thus resorting to `MissingNativeAppStateShim`, this will result in an exception: ```Cannot use 'AppState' module when native 'RCTAppState' is not included in the build. Either include it, or check 'AppState'.isAvailable before calling any methods.``` (Interestingly, `MissingNativeAppStateShim.currentState` did have a [default `null` value](118e88393e (diff-305b5180aa6ccc876ede6767de1fbfc4R192)) that was [later removed](a93b7a2da0 (diff-305b5180aa6ccc876ede6767de1fbfc4R186)).) **Update**: Following cpojer's suggestion of revertinga93b7a2da0. Title also updated to reflect this. [General] [Fixed] - Remove MissingNativeRCTNetworkingShim; revert MissingNativeAppStateShim Pull Request resolved: https://github.com/facebook/react-native/pull/24380 Differential Revision: D14932658 Pulled By: cpojer fbshipit-source-id: aef7ca566b3b8660eaed74a8ba3b6b0117b1200c
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
let register = function() {
|
|
// noop
|
|
};
|
|
|
|
if (__DEV__) {
|
|
const AppState = require('AppState');
|
|
const reactDevTools = require('react-devtools-core');
|
|
const getDevServer = require('getDevServer');
|
|
|
|
// 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,
|
|
};
|