Add a working RN build

This commit is contained in:
Dan Abramov
2017-03-16 19:10:46 +00:00
parent 04972cde8e
commit e4fcbecc1e
7 changed files with 85 additions and 8 deletions
+9 -2
View File
@@ -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 {
@@ -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;
@@ -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;
@@ -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;
+2 -1
View File
@@ -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 {};
}
}
+9 -1
View File
@@ -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) {
+12
View File
@@ -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;