Patch up for future React Sync

Reviewed By: spicyj, bvaughn

Differential Revision: D4523259

fbshipit-source-id: 317a26ce3e9e48553a7f7c856dd6b48038b4b2ea
This commit is contained in:
Sebastian Markbage 2017-02-08 14:38:37 -08:00 committed by Facebook Github Bot
parent 1ab104a759
commit c3b25c9059
9 changed files with 37 additions and 55 deletions

View File

@ -11,12 +11,13 @@
*/
'use strict';
const ReactNativeMount = require('ReactNativeMount');
/*
const getReactData = require('getReactData');
const INDENTATION_SIZE = 2;
const MAX_DEPTH = 2;
const MAX_STRING_LENGTH = 50;
*/
/**
* Dump all React Native root views and their content. This function tries
@ -32,6 +33,12 @@ function dumpReactTree() {
}
function getReactTree() {
// TODO(sema): Reenable tree dumps using the Fiber tree structure. #15945684
return (
'React tree dumps have been temporarily disabled while React is ' +
'upgraded to Fiber.'
);
/*
let output = '';
const rootIds = Object.getOwnPropertyNames(ReactNativeMount._instancesByContainerID);
for (const rootId of rootIds) {
@ -41,8 +48,10 @@ function getReactTree() {
output += `============ End root ID: ${rootId} ============\n`;
}
return output;
*/
}
/*
function dumpNode(node: Object, identation: number) {
const data = getReactData(node);
if (data.nodeType === 'Text') {
@ -101,7 +110,6 @@ function convertObject(object: Object, depth: number) {
if (!first) {
output += ', ';
}
// $FlowFixMe(>=0.28.0)
output += `${key}: ${convertValue(object[key], depth + 1)}`;
first = false;
}
@ -139,5 +147,6 @@ function possiblyEllipsis(value: string) {
function indent(size: number) {
return ' '.repeat(size * INDENTATION_SIZE);
}
*/
module.exports = dumpReactTree;

View File

@ -72,28 +72,6 @@ function setupDevtools() {
console.error('Failed to eval: ' + e.message);
return;
}
// This is breaking encapsulation of the React package. Move plz.
var ReactNativeComponentTree = require('ReactNativeComponentTree');
window.__REACT_DEVTOOLS_GLOBAL_HOOK__.inject({
ComponentTree: {
getClosestInstanceFromNode: function (node) {
return ReactNativeComponentTree.getClosestInstanceFromNode(node);
},
getNodeFromInstance: function (inst) {
// inst is an internal instance (but could be a composite)
while (inst._renderedComponent) {
inst = inst._renderedComponent;
}
if (inst) {
return ReactNativeComponentTree.getNodeFromInstance(inst);
} else {
return null;
}
}
},
Mount: require('ReactNativeMount'),
Reconciler: require('ReactReconciler')
});
ws.onmessage = handleMessage;
}
@ -109,7 +87,6 @@ function setupDevtools() {
// the devtools closed
if (data.$close || data.$error) {
closeListeners.forEach(fn => fn());
window.__REACT_DEVTOOLS_GLOBAL_HOOK__.emit('shutdown');
tryToConnect();
return;
}

View File

@ -20,7 +20,12 @@ function traverseOwnerTreeUp(hierarchy, instance) {
}
function findInstanceByNativeTag(nativeTag) {
return ReactNativeComponentTree.getInstanceFromNode(nativeTag);
var instance = ReactNativeComponentTree.getInstanceFromNode(nativeTag);
if (typeof instance.tag === 'number') {
// TODO(sema): We've disabled the inspector when using Fiber. Fix #15953531
return null;
}
return instance;
}
function getOwnerHierarchy(instance) {

View File

@ -18,14 +18,14 @@ function StyleSheetPropType(
shape: {[key: string]: ReactPropsCheckType}
): ReactPropsCheckType {
var shapePropType = createStrictShapeTypeChecker(shape);
return function(props, propName, componentName, location?) {
return function(props, propName, componentName, location?, ...rest) {
var newProps = props;
if (props[propName]) {
// Just make a dummy prop object with only the flattened style
newProps = {};
newProps[propName] = flattenStyle(props[propName]);
}
return shapePropType(newProps, propName, componentName, location);
return shapePropType(newProps, propName, componentName, location, ...rest);
};
}

View File

@ -12,13 +12,17 @@
'use strict';
var ImageStylePropTypes = require('ImageStylePropTypes');
var ReactPropTypeLocations = require('react/lib/ReactPropTypeLocations');
var ReactPropTypesSecret = require('react/lib/ReactPropTypesSecret');
var TextStylePropTypes = require('TextStylePropTypes');
var ViewStylePropTypes = require('ViewStylePropTypes');
var invariant = require('fbjs/lib/invariant');
// Hardcoded because this is a legit case but we don't want to load it from
// a private API. We might likely want to unify style sheet creation with how it
// is done in the DOM so this might move into React. I know what I'm doing so
// plz don't fire me.
const ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
class StyleSheetValidation {
static validateStyleProp(prop, style, caller) {
if (!__DEV__) {
@ -34,9 +38,9 @@ class StyleSheetValidation {
style,
prop,
caller,
ReactPropTypeLocations.prop,
'prop',
null,
ReactPropTypesSecret
ReactPropTypesSecret,
);
if (error) {
styleError(error.message, style, caller);

View File

@ -11,16 +11,13 @@
*/
'use strict';
var ReactPropTypeLocationNames = require('react/lib/ReactPropTypeLocationNames');
var ReactPropTypesSecret = require('react/lib/ReactPropTypesSecret');
var invariant = require('fbjs/lib/invariant');
var merge = require('merge');
function createStrictShapeTypeChecker(
shapeTypes: {[key: string]: ReactPropsCheckType}
): ReactPropsChainableTypeChecker {
function checkType(isRequired, props, propName, componentName, location?) {
function checkType(isRequired, props, propName, componentName, location?, ...rest) {
if (!props[propName]) {
if (isRequired) {
invariant(
@ -33,8 +30,7 @@ function createStrictShapeTypeChecker(
}
var propValue = props[propName];
var propType = typeof propValue;
var locationName =
location && ReactPropTypeLocationNames[location] || '(unknown)';
var locationName = location || '(unknown)';
if (propType !== 'object') {
invariant(
false,
@ -55,7 +51,7 @@ function createStrictShapeTypeChecker(
`\nValid keys: ` + JSON.stringify(Object.keys(shapeTypes), null, ' ')
);
}
var error = checker(propValue, key, componentName, location, null, ReactPropTypesSecret);
var error = checker(propValue, key, componentName, location, ...rest);
if (error) {
invariant(
false,
@ -69,9 +65,10 @@ function createStrictShapeTypeChecker(
props: {[key: string]: any},
propName: string,
componentName: string,
location?: string
location?: string,
...rest
): ?Error {
return checkType(false, props, propName, componentName, location);
return checkType(false, props, propName, componentName, location, ...rest);
}
chainedCheckType.isRequired = checkType.bind(null, true);
return chainedCheckType;

View File

@ -12,8 +12,6 @@
'use strict';
const UIManager = require('UIManager');
const ReactPropTypesSecret = require('react/lib/ReactPropTypesSecret');
const ReactPropTypeLocations = require('react/lib/ReactPropTypeLocations');
/**
* Adds a deprecation warning when the prop is used.
@ -22,7 +20,7 @@ function deprecatedPropType(
propType: ReactPropsCheckType,
explanation: string
): ReactPropsCheckType {
return function validate(props, propName, componentName) {
return function validate(props, propName, componentName, ...rest) {
// Don't warn for native components.
if (!UIManager[componentName] && props[propName] !== undefined) {
console.warn(`\`${propName}\` supplied to \`${componentName}\` has been deprecated. ${explanation}`);
@ -32,9 +30,7 @@ function deprecatedPropType(
props,
propName,
componentName,
ReactPropTypeLocations.prop,
null,
ReactPropTypesSecret
...rest
);
};
}

View File

@ -120,12 +120,6 @@ const ReactNative = {
// See http://facebook.github.io/react/docs/addons.html
addons: {
get LinkedStateMixin() {
if (__DEV__) {
addonWarn('LinkedStateMixin', 'react-addons-linked-state-mixin');
}
return require('react/lib/LinkedStateMixin');
},
get PureRenderMixin() {
if (__DEV__) {
addonWarn('PureRenderMixin', 'react-addons-pure-render-mixin');

View File

@ -27,7 +27,7 @@ jest
jest.setMock('ErrorUtils', require('ErrorUtils'));
jest
.mock('ReactNativeDefaultInjection')
.mock('InitializeCore')
.mock('Image', () => mockComponent('Image'))
.mock('Text', () => mockComponent('Text'))
.mock('TextInput', () => mockComponent('TextInput'))
@ -50,7 +50,7 @@ jest
Object.keys(dataBlob).forEach(key => {
this.items += dataBlob[key] && (
dataBlob[key].length || dataBlob[key].size || 0
)
);
});
} catch (e) {
this.items = 'unknown';