Remove avoidable vendor code

Updates the 'StyleSheetValidation' and 'ColorPropType' implementations
with the latest from React Native.
This commit is contained in:
Nicolas Gallagher
2017-06-05 20:06:19 -07:00
parent 77fd867421
commit ce4cc8a946
5 changed files with 48 additions and 74 deletions
+29 -23
View File
@@ -1,62 +1,68 @@
/* eslint-disable */
/** /**
* Copyright (c) 2016-present, Nicolas Gallagher.
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved. * 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 StyleSheetValidation
* @flow * @flow
*/ */
import ImageStylePropTypes from '../../components/Image/ImageStylePropTypes'; import ImageStylePropTypes from '../../components/Image/ImageStylePropTypes';
import ReactPropTypeLocationNames from '../../vendor/ReactPropTypeLocationNames';
import ReactPropTypesSecret from '../../vendor/ReactPropTypesSecret';
import TextInputStylePropTypes from '../../components/TextInput/TextInputStylePropTypes'; import TextInputStylePropTypes from '../../components/TextInput/TextInputStylePropTypes';
import TextStylePropTypes from '../../components/Text/TextStylePropTypes'; import TextStylePropTypes from '../../components/Text/TextStylePropTypes';
import ViewStylePropTypes from '../../components/View/ViewStylePropTypes'; import ViewStylePropTypes from '../../components/View/ViewStylePropTypes';
import warning from 'fbjs/lib/warning'; import warning from 'fbjs/lib/warning';
import { oneOf, string } from 'prop-types'; import { oneOf, string } from 'prop-types';
// 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 { class StyleSheetValidation {
static validateStyleProp(prop, style, caller) { static validateStyleProp(prop, style, caller) {
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
if (allStylePropTypes[prop] === undefined) { if (allStylePropTypes[prop] === undefined) {
var message1 = '"' + prop + '" is not a valid style property.'; const message1 = '"' + prop + '" is not a valid style property.';
var message2 = const message2 =
'\nValid style props: ' + '\nValid style props: ' +
JSON.stringify(Object.keys(allStylePropTypes).sort(), null, ' '); JSON.stringify(Object.keys(allStylePropTypes).sort(), null, ' ');
styleError(message1, style, caller, message2); styleError(message1, style, caller, message2);
} else { }
var error = allStylePropTypes[prop]( const error = allStylePropTypes[prop](
style, style,
prop, prop,
caller, caller,
ReactPropTypeLocationNames.prop, 'prop',
null, null,
ReactPropTypesSecret ReactPropTypesSecret
); );
if (error) { if (error) {
styleError(error.message, style, caller); styleError(error.message, style, caller);
}
} }
} }
} }
static validateStyle(name, styles) { static validateStyle(name, styles) {
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
for (var prop in styles[name]) { for (const prop in styles[name]) {
StyleSheetValidation.validateStyleProp(prop, styles[name], 'StyleSheet ' + name); StyleSheetValidation.validateStyleProp(prop, styles[name], 'StyleSheet ' + name);
} }
} }
} }
static addValidStylePropTypes(stylePropTypes) { static addValidStylePropTypes(stylePropTypes) {
for (var key in stylePropTypes) { for (const key in stylePropTypes) {
allStylePropTypes[key] = stylePropTypes[key]; allStylePropTypes[key] = stylePropTypes[key];
} }
} }
} }
var styleError = function(message1, style, caller?, message2?) { const styleError = function(message1, style, caller?, message2?) {
warning( warning(
false, false,
message1 + message1 +
@@ -68,7 +74,7 @@ var styleError = function(message1, style, caller?, message2?) {
); );
}; };
var allStylePropTypes = {}; const allStylePropTypes = {};
StyleSheetValidation.addValidStylePropTypes(ImageStylePropTypes); StyleSheetValidation.addValidStylePropTypes(ImageStylePropTypes);
StyleSheetValidation.addValidStylePropTypes(TextStylePropTypes); StyleSheetValidation.addValidStylePropTypes(TextStylePropTypes);
@@ -53,7 +53,6 @@ var PRESS_RETENTION_OFFSET = { top: 20, left: 20, right: 20, bottom: 30 };
* ``` * ```
*/ */
var TouchableOpacity = createReactClass({ var TouchableOpacity = createReactClass({
displayName: 'TouchableOpacity',
mixins: [TimerMixin, Touchable.Mixin, NativeMethodsMixin], mixins: [TimerMixin, Touchable.Mixin, NativeMethodsMixin],
propTypes: { propTypes: {
+19 -20
View File
@@ -1,25 +1,23 @@
/* eslint-disable */
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * 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 * 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. * of patent rights can be found in the PATENTS file in the same directory.
* *
* @providesModule ColorPropType * @providesModule ColorPropType
*/ * @flow
*/
var colorPropType = function(isRequired, props, propName, componentName, location, propFullName) { const colorPropType = function(isRequired, props, propName, componentName, location, propFullName) {
var normalizeColor = require('normalize-css-color'); const normalizeColor = require('normalize-css-color');
var ReactPropTypeLocationNames = require('../vendor/ReactPropTypeLocationNames'); const color = props[propName];
var color = props[propName];
if (color === undefined || color === null) { if (color === undefined || color === null) {
if (isRequired) { if (isRequired) {
var locationName = ReactPropTypeLocationNames[location];
return new Error( return new Error(
'Required ' + 'Required ' +
locationName + location +
' `' + ' `' +
(propFullName || propName) + (propFullName || propName) +
'` was not specified in `' + '` was not specified in `' +
@@ -42,10 +40,9 @@ var colorPropType = function(isRequired, props, propName, componentName, locatio
} }
if (normalizeColor(color) === null) { if (normalizeColor(color) === null) {
var locationName = ReactPropTypeLocationNames[location];
return new Error( return new Error(
'Invalid ' + 'Invalid ' +
locationName + location +
' `' + ' `' +
(propFullName || propName) + (propFullName || propName) +
'` supplied to `' + '` supplied to `' +
@@ -70,11 +67,13 @@ var colorPropType = function(isRequired, props, propName, componentName, locatio
} }
}; };
let ColorPropType;
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
var ColorPropType = colorPropType.bind(null, false /* isRequired */); ColorPropType = colorPropType.bind(null, false /* isRequired */);
ColorPropType.isRequired = colorPropType.bind(null, true /* isRequired */); ColorPropType.isRequired = colorPropType.bind(null, true /* isRequired */);
} else { } else {
var ColorPropType = function() {}; ColorPropType = function() {};
} }
module.exports = ColorPropType; module.exports = ColorPropType;
-20
View File
@@ -1,20 +0,0 @@
/**
* 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.
*/
let ReactPropTypeLocationNames = {};
if (process.env.NODE_ENV !== 'production') {
ReactPropTypeLocationNames = {
prop: 'prop',
context: 'context',
childContext: 'child context'
};
}
module.exports = ReactPropTypeLocationNames;
-10
View File
@@ -1,10 +0,0 @@
/**
* 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.
*/
const ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
module.exports = ReactPropTypesSecret;