Skip to content

Commit

Permalink
Patch up for future React Sync
Browse files Browse the repository at this point in the history
Reviewed By: spicyj, bvaughn

Differential Revision: D4523259

fbshipit-source-id: 317a26ce3e9e48553a7f7c856dd6b48038b4b2ea
  • Loading branch information
sebmarkbage authored and facebook-github-bot committed Feb 8, 2017
1 parent 1ab104a commit c3b25c9
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 55 deletions.
13 changes: 11 additions & 2 deletions Libraries/BugReporting/dumpReactTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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') {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -139,5 +147,6 @@ function possiblyEllipsis(value: string) {
function indent(size: number) {
return ' '.repeat(size * INDENTATION_SIZE);
}
*/

module.exports = dumpReactTree;
23 changes: 0 additions & 23 deletions Libraries/Core/Devtools/setupDevtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down
7 changes: 6 additions & 1 deletion Libraries/Inspector/InspectorUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions Libraries/StyleSheet/StyleSheetPropType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}

Expand Down
12 changes: 8 additions & 4 deletions Libraries/StyleSheet/StyleSheetValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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__) {
Expand All @@ -34,9 +38,9 @@ class StyleSheetValidation {
style,
prop,
caller,
ReactPropTypeLocations.prop,
'prop',
null,
ReactPropTypesSecret
ReactPropTypesSecret,
);
if (error) {
styleError(error.message, style, caller);
Expand Down
15 changes: 6 additions & 9 deletions Libraries/Utilities/createStrictShapeTypeChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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;
Expand Down
8 changes: 2 additions & 6 deletions Libraries/Utilities/deprecatedPropType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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}`);
Expand All @@ -32,9 +30,7 @@ function deprecatedPropType(
props,
propName,
componentName,
ReactPropTypeLocations.prop,
null,
ReactPropTypesSecret
...rest
);
};
}
Expand Down
6 changes: 0 additions & 6 deletions Libraries/react-native/react-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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';
Expand Down

0 comments on commit c3b25c9

Please sign in to comment.