mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
RN: Delete StyleSheetValidation
Summary: Deletes `StyleSheetValidation` because it is `prop-types` in disguise. Changelog: [General][Removed] - `StyleSheet.create` will no longer do DEV-time validation. Reviewed By: TheSavior Differential Revision: D29019310 fbshipit-source-id: bfe886d8dc09a1aa8dac4a73bfd62f481e3eb9e9
This commit is contained in:
1 parent
052b3e3faa
commit
2e8c0bd7ea
3 files changed
-108
No files matched your search
@@ -12,7 +12,6 @@
|
||||
|
||||
const PixelRatio = require('../Utilities/PixelRatio');
|
||||
const ReactNativeStyleAttributes = require('../Components/View/ReactNativeStyleAttributes');
|
||||
const StyleSheetValidation = require('./StyleSheetValidation');
|
||||
|
||||
const flatten = require('./flattenStyle');
|
||||
|
||||
@@ -363,7 +362,6 @@ module.exports = {
|
||||
// return value as a number (even though it was opaque).
|
||||
if (__DEV__) {
|
||||
for (const key in obj) {
|
||||
StyleSheetValidation.validateStyle(key, obj);
|
||||
if (obj[key]) {
|
||||
Object.freeze(obj[key]);
|
||||
}
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const DeprecatedImageStylePropTypes = require('../DeprecatedPropTypes/DeprecatedImageStylePropTypes');
|
||||
const DeprecatedTextStylePropTypes = require('../DeprecatedPropTypes/DeprecatedTextStylePropTypes');
|
||||
const DeprecatedViewStylePropTypes = require('../DeprecatedPropTypes/DeprecatedViewStylePropTypes');
|
||||
|
||||
const invariant = require('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: string, style: Object, caller: string) {
|
||||
if (!__DEV__ || global.__RCTProfileIsProfiling) {
|
||||
return;
|
||||
}
|
||||
if (allStylePropTypes[prop] === undefined) {
|
||||
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);
|
||||
}
|
||||
const error = allStylePropTypes[prop](
|
||||
style,
|
||||
prop,
|
||||
caller,
|
||||
'prop',
|
||||
null,
|
||||
ReactPropTypesSecret,
|
||||
);
|
||||
if (error) {
|
||||
styleError(error.message, style, caller);
|
||||
}
|
||||
}
|
||||
|
||||
static validateStyle(name: string, styles: Object) {
|
||||
if (!__DEV__ || global.__RCTProfileIsProfiling) {
|
||||
return;
|
||||
}
|
||||
if (!styles[name]) {
|
||||
return;
|
||||
}
|
||||
const styleProps = Object.keys(styles[name]);
|
||||
for (const prop of styleProps) {
|
||||
StyleSheetValidation.validateStyleProp(
|
||||
prop,
|
||||
styles[name],
|
||||
'StyleSheet ' + name,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/* $FlowFixMe[signature-verification-failure] (>=0.85.0 site=react_native_fb)
|
||||
* This comment suppresses an error found when Flow v0.85 was deployed. To
|
||||
* see the error, delete this comment and run Flow. */
|
||||
static addValidStylePropTypes(stylePropTypes) {
|
||||
if (!__DEV__ || global.__RCTProfileIsProfiling) {
|
||||
return;
|
||||
}
|
||||
for (const key in stylePropTypes) {
|
||||
allStylePropTypes[key] = stylePropTypes[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const styleError = function(message1, style, caller?, message2?) {
|
||||
invariant(
|
||||
false,
|
||||
message1 +
|
||||
'\n' +
|
||||
(caller || '<<unknown>>') +
|
||||
': ' +
|
||||
JSON.stringify(style, null, ' ') +
|
||||
(message2 || ''),
|
||||
);
|
||||
};
|
||||
|
||||
const allStylePropTypes = {};
|
||||
|
||||
if (__DEV__ && !global.__RCTProfileIsProfiling) {
|
||||
StyleSheetValidation.addValidStylePropTypes(DeprecatedImageStylePropTypes);
|
||||
StyleSheetValidation.addValidStylePropTypes(DeprecatedTextStylePropTypes);
|
||||
StyleSheetValidation.addValidStylePropTypes(DeprecatedViewStylePropTypes);
|
||||
}
|
||||
|
||||
module.exports = StyleSheetValidation;
|
||||
@@ -11,15 +11,9 @@
|
||||
'use strict';
|
||||
|
||||
const StyleSheet = require('../StyleSheet');
|
||||
const StyleSheetValidation = require('../StyleSheetValidation');
|
||||
const flattenStyle = require('../flattenStyle');
|
||||
|
||||
function getFixture() {
|
||||
StyleSheetValidation.addValidStylePropTypes({
|
||||
styleA: () => {},
|
||||
styleB: () => {},
|
||||
});
|
||||
|
||||
return StyleSheet.create({
|
||||
elementA: {
|
||||
styleA: 'moduleA/elementA/styleA',
|
||||
|
||||
Reference in new issue
Block a user