From 59445a625962d7be4c7c3e98defc8a31f8761ec1 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Tue, 4 Apr 2017 16:02:20 +0100 Subject: [PATCH] Hack around to fix RN bundle --- scripts/rollup/bundles.js | 2 ++ src/renderers/native/NativeMethodsMixin.js | 4 +--- src/renderers/native/ReactNative.js | 3 +++ src/renderers/native/takeSnapshot.js | 10 +++++++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/rollup/bundles.js b/scripts/rollup/bundles.js index a65dc25ae1e29..b7971dfa64123 100644 --- a/scripts/rollup/bundles.js +++ b/scripts/rollup/bundles.js @@ -227,9 +227,11 @@ const bundles = [ }, entry: 'src/renderers/native/ReactNative.js', externals: [ + 'ExceptionsManager', 'InitializeCore', 'RCTEventEmitter', 'UIManager', + 'View', 'deepDiffer', 'flattenStyle', 'TextInputState', diff --git a/src/renderers/native/NativeMethodsMixin.js b/src/renderers/native/NativeMethodsMixin.js index f1dec131c5446..e864f6d9c8937 100644 --- a/src/renderers/native/NativeMethodsMixin.js +++ b/src/renderers/native/NativeMethodsMixin.js @@ -21,8 +21,7 @@ var findNodeHandle = require('findNodeHandle'); var ReactNative; -// TODO: figure this out when we work on flat bundles in RN. -// This might not be needed after all. +// Works around a circular dependency in flat bundle. function injectReactNative(RN: $FlowFixMe) { ReactNative = RN; } @@ -159,7 +158,6 @@ var NativeMethodsMixin = { TextInputState.blurTextInput(ReactNative.findNodeHandle(this)); }, - // Temporary hack to avoid a circular dependency __injectReactNative: injectReactNative, }; diff --git a/src/renderers/native/ReactNative.js b/src/renderers/native/ReactNative.js index 8a37938bd971a..380c8bad0ddd7 100644 --- a/src/renderers/native/ReactNative.js +++ b/src/renderers/native/ReactNative.js @@ -12,12 +12,15 @@ var ReactNativeFeatureFlags = require('ReactNativeFeatureFlags'); var NativeMethodsMixin = require('NativeMethodsMixin'); +var takeSnapshot = require('takeSnapshot'); var ReactNative = ReactNativeFeatureFlags.useFiber ? require('ReactNativeFiber') : require('ReactNativeStack'); +// Work around circular dependencies NativeMethodsMixin.__injectReactNative(ReactNative); +takeSnapshot.__injectReactNative(ReactNative); ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = { createReactNativeComponentClass: require('createReactNativeComponentClass'), diff --git a/src/renderers/native/takeSnapshot.js b/src/renderers/native/takeSnapshot.js index 98608c83e5ff3..f29e2bdc3284d 100644 --- a/src/renderers/native/takeSnapshot.js +++ b/src/renderers/native/takeSnapshot.js @@ -11,9 +11,15 @@ */ 'use strict'; -var ReactNative = require('ReactNative'); var UIManager = require('UIManager'); +var ReactNative; + +// Works around a circular dependency in flat bundle. +function injectReactNative(RN: $FlowFixMe) { + ReactNative = RN; +} + import type {Element} from 'React'; /** @@ -51,4 +57,6 @@ function takeSnapshot( return UIManager.__takeSnapshot(view, options); } +takeSnapshot.__injectReactNative = injectReactNative; + module.exports = takeSnapshot;