diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index 410a65532d..f97c82939f 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -146,10 +146,17 @@ function getCommonJsConfig(bundleType) { switch (bundleType) { case bundleTypes.PROD: case bundleTypes.DEV: + case bundleTypes.NODE: return {}; - case bundleTypes.NODE: // TODO: why does it share settings with FB? + case bundleTypes.RN: + return { + ignore: [ + // This imports NativeMethodsMixin, causing + // a circular dependency. + 'View', + ] + }; case bundleTypes.FB: - case bundleTypes.RN: // TODO: I haven't checked if this is right // Modules we don't want to inline in the bundle. // Force them to stay as require()s in the output. return { diff --git a/scripts/rollup/forwarding-native/ReactNativeComponentTree.js b/scripts/rollup/forwarding-native/ReactNativeComponentTree.js new file mode 100644 index 0000000000..54192a5d9d --- /dev/null +++ b/scripts/rollup/forwarding-native/ReactNativeComponentTree.js @@ -0,0 +1,19 @@ +/** + * Copyright 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @providesModule ReactNativeComponentTree + * @flow + */ + +'use strict'; + +const { + __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, +} = require('ReactNative'); + +module.exports = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactNativeComponentTree; diff --git a/scripts/rollup/forwarding-native/ReactPerf.js b/scripts/rollup/forwarding-native/ReactPerf.js new file mode 100644 index 0000000000..d07ad1c569 --- /dev/null +++ b/scripts/rollup/forwarding-native/ReactPerf.js @@ -0,0 +1,19 @@ +/** + * Copyright 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @providesModule ReactPerf + * @flow + */ + +'use strict'; + +const { + __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, +} = require('ReactNative'); + +module.exports = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactPerf; diff --git a/scripts/rollup/forwarding-native/findNodeHandle.js b/scripts/rollup/forwarding-native/findNodeHandle.js index 501da7a412..02030ad192 100644 --- a/scripts/rollup/forwarding-native/findNodeHandle.js +++ b/scripts/rollup/forwarding-native/findNodeHandle.js @@ -12,9 +12,20 @@ 'use strict'; -const { - __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, -} = require('ReactNative'); +// While ReactNative renderer bundle is initializing, some +// code (e.g. UIManager) imports from ReactNative. -module.exports = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.findNodeHandle; +// We use an indirection to avoid a circular dependency. + +let realFindNodeHandle = null; + +function findNodeHandle(componentOrHandle: any): ?number { + if (realFindNodeHandle === null) { + realFindNodeHandle = require('ReactNative'). + __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.findNodeHandle; + } + return realFindNodeHandle(componentOrHandle); +} + +module.exports = findNodeHandle; \ No newline at end of file diff --git a/scripts/rollup/modules.js b/scripts/rollup/modules.js index abb602918b..e1be61d22d 100644 --- a/scripts/rollup/modules.js +++ b/scripts/rollup/modules.js @@ -59,7 +59,6 @@ function getInternalModules(bundleType) { }; case bundleTypes.NODE: case bundleTypes.FB: - case bundleTypes.RN: // TODO: I haven't checked if this is right return { // we tell Rollup where these files are located internally, otherwise // it doesn't pick them up and assumes they're external @@ -69,6 +68,8 @@ function getInternalModules(bundleType) { 'react/lib/ReactDebugCurrentFrame': resolve('./src/isomorphic/classic/element/ReactDebugCurrentFrame.js'), 'react/lib/ReactComponentTreeHook': resolve('./src/isomorphic/hooks/ReactComponentTreeHook.js'), }; + case bundleTypes.RN: + return {}; } } diff --git a/src/renderers/native/NativeMethodsMixin.js b/src/renderers/native/NativeMethodsMixin.js index 25062816e3..a7907da9ba 100644 --- a/src/renderers/native/NativeMethodsMixin.js +++ b/src/renderers/native/NativeMethodsMixin.js @@ -11,7 +11,6 @@ */ 'use strict'; -var ReactNative = require('ReactNative'); var ReactNativeAttributePayload = require('ReactNativeAttributePayload'); var TextInputState = require('TextInputState'); var UIManager = require('UIManager'); @@ -41,6 +40,12 @@ type MeasureLayoutOnSuccessCallback = ( height: number, ) => void; +var ReactNative; + +function injectReactNative(RN) { + ReactNative = RN; +} + function warnForStyleProps(props, validAttributes) { for (var key in validAttributes.style) { if (!(validAttributes[key] || props[key] === undefined)) { @@ -174,6 +179,9 @@ var NativeMethodsMixin = { blur: function() { TextInputState.blurTextInput(ReactNative.findNodeHandle(this)); }, + + // Temporary hack to avoid a circular dependency + __injectReactNative: injectReactNative, }; function throwOnStylesProp(component, props) { diff --git a/src/renderers/native/ReactNative.js b/src/renderers/native/ReactNative.js index 764acd8086..36869a9641 100644 --- a/src/renderers/native/ReactNative.js +++ b/src/renderers/native/ReactNative.js @@ -11,12 +11,24 @@ 'use strict'; var ReactNativeStack = require('ReactNativeStack'); +var NativeMethodsMixin = require('NativeMethodsMixin'); // TODO (bvaughn) Enable Fiber experiement via ReactNativeFeatureFlags var ReactNative = ReactNativeStack; +// TODO: unroll the circular dependency +NativeMethodsMixin.__injectReactNative(ReactNative); + ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = { + createReactNativeComponentClass: require('createReactNativeComponentClass'), + findNodeHandle: require('findNodeHandle'), + NativeMethodsMixin: require('NativeMethodsMixin'), + ReactDebugTool: require('ReactDebugTool'), + ReactErrorUtils: require('ReactErrorUtils'), + ReactNativeComponentTree: require('ReactNativeComponentTree'), ReactNativePropRegistry: require('ReactNativePropRegistry'), + ReactPerf: require('ReactPerf'), + TouchHistoryMath: require('TouchHistoryMath'), }; module.exports = ReactNative;