mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-03-29 00:38:18 +08:00
Remove avoidable vendor code
Updates the 'StyleSheetValidation' and 'ColorPropType' implementations with the latest from React Native.
This commit is contained in:
@@ -1,62 +1,68 @@
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Copyright (c) 2016-present, Nicolas Gallagher.
|
||||
* Copyright (c) 2015-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 StyleSheetValidation
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import ImageStylePropTypes from '../../components/Image/ImageStylePropTypes';
|
||||
import ReactPropTypeLocationNames from '../../vendor/ReactPropTypeLocationNames';
|
||||
import ReactPropTypesSecret from '../../vendor/ReactPropTypesSecret';
|
||||
import TextInputStylePropTypes from '../../components/TextInput/TextInputStylePropTypes';
|
||||
import TextStylePropTypes from '../../components/Text/TextStylePropTypes';
|
||||
import ViewStylePropTypes from '../../components/View/ViewStylePropTypes';
|
||||
import warning from 'fbjs/lib/warning';
|
||||
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 {
|
||||
static validateStyleProp(prop, style, caller) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (allStylePropTypes[prop] === undefined) {
|
||||
var message1 = '"' + prop + '" is not a valid style property.';
|
||||
var message2 =
|
||||
const message1 = '"' + prop + '" is not a valid style property.';
|
||||
const message2 =
|
||||
'\nValid style props: ' +
|
||||
JSON.stringify(Object.keys(allStylePropTypes).sort(), null, ' ');
|
||||
styleError(message1, style, caller, message2);
|
||||
} else {
|
||||
var error = allStylePropTypes[prop](
|
||||
style,
|
||||
prop,
|
||||
caller,
|
||||
ReactPropTypeLocationNames.prop,
|
||||
null,
|
||||
ReactPropTypesSecret
|
||||
);
|
||||
if (error) {
|
||||
styleError(error.message, style, caller);
|
||||
}
|
||||
}
|
||||
const error = allStylePropTypes[prop](
|
||||
style,
|
||||
prop,
|
||||
caller,
|
||||
'prop',
|
||||
null,
|
||||
ReactPropTypesSecret
|
||||
);
|
||||
if (error) {
|
||||
styleError(error.message, style, caller);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static validateStyle(name, styles) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static addValidStylePropTypes(stylePropTypes) {
|
||||
for (var key in stylePropTypes) {
|
||||
for (const key in stylePropTypes) {
|
||||
allStylePropTypes[key] = stylePropTypes[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var styleError = function(message1, style, caller?, message2?) {
|
||||
const styleError = function(message1, style, caller?, message2?) {
|
||||
warning(
|
||||
false,
|
||||
message1 +
|
||||
@@ -68,7 +74,7 @@ var styleError = function(message1, style, caller?, message2?) {
|
||||
);
|
||||
};
|
||||
|
||||
var allStylePropTypes = {};
|
||||
const allStylePropTypes = {};
|
||||
|
||||
StyleSheetValidation.addValidStylePropTypes(ImageStylePropTypes);
|
||||
StyleSheetValidation.addValidStylePropTypes(TextStylePropTypes);
|
||||
|
||||
@@ -53,7 +53,6 @@ var PRESS_RETENTION_OFFSET = { top: 20, left: 20, right: 20, bottom: 30 };
|
||||
* ```
|
||||
*/
|
||||
var TouchableOpacity = createReactClass({
|
||||
displayName: 'TouchableOpacity',
|
||||
mixins: [TimerMixin, Touchable.Mixin, NativeMethodsMixin],
|
||||
|
||||
propTypes: {
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Copyright (c) 2015-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 ColorPropType
|
||||
*/
|
||||
* Copyright (c) 2015-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 ColorPropType
|
||||
* @flow
|
||||
*/
|
||||
|
||||
var colorPropType = function(isRequired, props, propName, componentName, location, propFullName) {
|
||||
var normalizeColor = require('normalize-css-color');
|
||||
var ReactPropTypeLocationNames = require('../vendor/ReactPropTypeLocationNames');
|
||||
var color = props[propName];
|
||||
const colorPropType = function(isRequired, props, propName, componentName, location, propFullName) {
|
||||
const normalizeColor = require('normalize-css-color');
|
||||
const color = props[propName];
|
||||
if (color === undefined || color === null) {
|
||||
if (isRequired) {
|
||||
var locationName = ReactPropTypeLocationNames[location];
|
||||
return new Error(
|
||||
'Required ' +
|
||||
locationName +
|
||||
location +
|
||||
' `' +
|
||||
(propFullName || propName) +
|
||||
'` was not specified in `' +
|
||||
@@ -42,10 +40,9 @@ var colorPropType = function(isRequired, props, propName, componentName, locatio
|
||||
}
|
||||
|
||||
if (normalizeColor(color) === null) {
|
||||
var locationName = ReactPropTypeLocationNames[location];
|
||||
return new Error(
|
||||
'Invalid ' +
|
||||
locationName +
|
||||
location +
|
||||
' `' +
|
||||
(propFullName || propName) +
|
||||
'` supplied to `' +
|
||||
@@ -70,11 +67,13 @@ var colorPropType = function(isRequired, props, propName, componentName, locatio
|
||||
}
|
||||
};
|
||||
|
||||
let ColorPropType;
|
||||
|
||||
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 */);
|
||||
} else {
|
||||
var ColorPropType = function() {};
|
||||
ColorPropType = function() {};
|
||||
}
|
||||
|
||||
module.exports = ColorPropType;
|
||||
|
||||
20
src/vendor/ReactPropTypeLocationNames/index.js
vendored
20
src/vendor/ReactPropTypeLocationNames/index.js
vendored
@@ -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
src/vendor/ReactPropTypesSecret/index.js
vendored
10
src/vendor/ReactPropTypesSecret/index.js
vendored
@@ -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;
|
||||
Reference in New Issue
Block a user