From 1dc769bfb11f50a38bc72579b5716747497ae08a Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Thu, 7 Jul 2016 22:14:08 -0700 Subject: [PATCH] move propTypes and normalizeColor --- src/apis/StyleSheet/TransformPropTypes.js | 49 ------------------ src/components/Image/ImageStylePropTypes.js | 8 +-- src/components/Image/index.js | 2 +- src/components/ScrollView/index.js | 2 +- src/components/Text/TextStylePropTypes.js | 2 +- src/components/Text/index.js | 2 +- src/components/Touchable/Touchable.js | 2 +- src/components/Touchable/TouchableBounce.js | 2 +- .../Touchable/TouchableHighlight.js | 2 +- .../Touchable/TouchableWithoutFeedback.js | 2 +- src/components/View/ViewStylePropTypes.js | 8 +-- src/components/View/index.js | 2 +- src/index.js | 6 +-- .../normalizeColor/index.js} | 0 .../BorderPropTypes.js | 2 +- .../StyleSheet => propTypes}/ColorPropType.js | 2 +- .../EdgeInsetsPropType.js | 0 .../LayoutPropTypes.js | 0 .../StyleSheet => propTypes}/PointPropType.js | 0 .../StyleSheetPropType.js | 2 +- src/propTypes/TransformPropTypes.js | 50 +++++++++++++++++++ .../createStrictShapeTypeChecker.js | 0 22 files changed, 73 insertions(+), 72 deletions(-) delete mode 100644 src/apis/StyleSheet/TransformPropTypes.js rename src/{apis/StyleSheet/normalizeColor.js => modules/normalizeColor/index.js} (100%) rename src/{apis/StyleSheet => propTypes}/BorderPropTypes.js (92%) rename src/{apis/StyleSheet => propTypes}/ColorPropType.js (97%) rename src/{apis/StyleSheet => propTypes}/EdgeInsetsPropType.js (100%) rename src/{apis/StyleSheet => propTypes}/LayoutPropTypes.js (100%) rename src/{apis/StyleSheet => propTypes}/PointPropType.js (100%) rename src/{apis/StyleSheet => propTypes}/StyleSheetPropType.js (92%) create mode 100644 src/propTypes/TransformPropTypes.js rename src/{apis/StyleSheet => propTypes}/createStrictShapeTypeChecker.js (100%) diff --git a/src/apis/StyleSheet/TransformPropTypes.js b/src/apis/StyleSheet/TransformPropTypes.js deleted file mode 100644 index cccee96b..00000000 --- a/src/apis/StyleSheet/TransformPropTypes.js +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * @flow - */ - -import { PropTypes } from 'react' - -const ArrayOfNumberPropType = PropTypes.arrayOf(PropTypes.number) -const numberOrString = PropTypes.oneOfType([ PropTypes.number, PropTypes.string ]) - -const TransformMatrixPropType = function ( - props : Object, - propName : string, - componentName : string -) : ?Error { - if (props.transform && props.transformMatrix) { - return new Error( - 'transformMatrix and transform styles cannot be used on the same ' + - 'component' - ) - } - return ArrayOfNumberPropType(props, propName, componentName) -} - -const TransformPropTypes = { - transform: PropTypes.arrayOf( - PropTypes.oneOfType([ - PropTypes.shape({ perspective: numberOrString }), - PropTypes.shape({ rotate: numberOrString }), - PropTypes.shape({ rotateX: numberOrString }), - PropTypes.shape({ rotateY: numberOrString }), - PropTypes.shape({ rotateZ: numberOrString }), - PropTypes.shape({ scale: numberOrString }), - PropTypes.shape({ scaleX: numberOrString }), - PropTypes.shape({ scaleY: numberOrString }), - PropTypes.shape({ skewX: numberOrString }), - PropTypes.shape({ skewY: numberOrString }), - PropTypes.shape({ translateX: numberOrString }), - PropTypes.shape({ translateY: numberOrString }), - PropTypes.shape({ translateZ: numberOrString }), - PropTypes.shape({ translate3d: PropTypes.string }) - ]) - ), - transformMatrix: TransformMatrixPropType -} - -module.exports = TransformPropTypes diff --git a/src/components/Image/ImageStylePropTypes.js b/src/components/Image/ImageStylePropTypes.js index 9f7306b2..6a7f7332 100644 --- a/src/components/Image/ImageStylePropTypes.js +++ b/src/components/Image/ImageStylePropTypes.js @@ -1,8 +1,8 @@ import { PropTypes } from 'react' -import BorderPropTypes from '../../apis/StyleSheet/BorderPropTypes' -import ColorPropType from '../../apis/StyleSheet/ColorPropType' -import LayoutPropTypes from '../../apis/StyleSheet/LayoutPropTypes' -import TransformPropTypes from '../../apis/StyleSheet/TransformPropTypes' +import BorderPropTypes from '../../propTypes/BorderPropTypes' +import ColorPropType from '../../propTypes/ColorPropType' +import LayoutPropTypes from '../../propTypes/LayoutPropTypes' +import TransformPropTypes from '../../propTypes/TransformPropTypes' import ImageResizeMode from './ImageResizeMode' const hiddenOrVisible = PropTypes.oneOf([ 'hidden', 'visible' ]) diff --git a/src/components/Image/index.js b/src/components/Image/index.js index 3d1aa171..7c801c8d 100644 --- a/src/components/Image/index.js +++ b/src/components/Image/index.js @@ -6,7 +6,7 @@ import ImageStylePropTypes from './ImageStylePropTypes' import resolveAssetSource from './resolveAssetSource' import React, { Component, PropTypes } from 'react' import StyleSheet from '../../apis/StyleSheet' -import StyleSheetPropType from '../../apis/StyleSheet/StyleSheetPropType' +import StyleSheetPropType from '../../propTypes/StyleSheetPropType' import View from '../View' const STATUS_ERRORED = 'ERRORED' diff --git a/src/components/ScrollView/index.js b/src/components/ScrollView/index.js index 9091e2d7..ce51ff5f 100644 --- a/src/components/ScrollView/index.js +++ b/src/components/ScrollView/index.js @@ -13,7 +13,7 @@ import ReactDOM from 'react-dom' import ScrollResponder from '../../modules/ScrollResponder' import ScrollViewBase from './ScrollViewBase' import StyleSheet from '../../apis/StyleSheet' -import StyleSheetPropType from '../../apis/StyleSheet/StyleSheetPropType' +import StyleSheetPropType from '../../propTypes/StyleSheetPropType' import View from '../View' import ViewStylePropTypes from '../View/ViewStylePropTypes' diff --git a/src/components/Text/TextStylePropTypes.js b/src/components/Text/TextStylePropTypes.js index 71f464a2..811250f1 100644 --- a/src/components/Text/TextStylePropTypes.js +++ b/src/components/Text/TextStylePropTypes.js @@ -1,5 +1,5 @@ import { PropTypes } from 'react' -import ColorPropType from '../../apis/StyleSheet/ColorPropType' +import ColorPropType from '../../propTypes/ColorPropType' import ViewStylePropTypes from '../View/ViewStylePropTypes' const { number, oneOf, oneOfType, string } = PropTypes diff --git a/src/components/Text/index.js b/src/components/Text/index.js index 937441a6..b9862a33 100644 --- a/src/components/Text/index.js +++ b/src/components/Text/index.js @@ -2,7 +2,7 @@ import applyNativeMethods from '../../modules/applyNativeMethods' import createReactDOMComponent from '../../modules/createReactDOMComponent' import { Component, PropTypes } from 'react' import StyleSheet from '../../apis/StyleSheet' -import StyleSheetPropType from '../../apis/StyleSheet/StyleSheetPropType' +import StyleSheetPropType from '../../propTypes/StyleSheetPropType' import TextStylePropTypes from './TextStylePropTypes' class Text extends Component { diff --git a/src/components/Touchable/Touchable.js b/src/components/Touchable/Touchable.js index f46f1f74..ab779f48 100644 --- a/src/components/Touchable/Touchable.js +++ b/src/components/Touchable/Touchable.js @@ -15,7 +15,7 @@ /* @edit start */ const BoundingDimensions = require('./BoundingDimensions'); const keyMirror = require('fbjs/lib/keyMirror'); -const normalizeColor = require('../../apis/StyleSheet/normalizeColor'); +const normalizeColor = require('../../modules/normalizeColor'); const Position = require('./Position'); const React = require('react'); const TouchEventUtils = require('fbjs/lib/TouchEventUtils'); diff --git a/src/components/Touchable/TouchableBounce.js b/src/components/Touchable/TouchableBounce.js index 7aec0b39..ee7f2e53 100644 --- a/src/components/Touchable/TouchableBounce.js +++ b/src/components/Touchable/TouchableBounce.js @@ -13,7 +13,7 @@ 'use strict'; var Animated = require('../../apis/Animated'); -var EdgeInsetsPropType = require('../../apis/StyleSheet/EdgeInsetsPropType'); +var EdgeInsetsPropType = require('../../propTypes/EdgeInsetsPropType'); var NativeMethodsMixin = require('../../modules/NativeMethodsMixin'); var React = require('react'); var StyleSheet = require('../../apis/StyleSheet'); diff --git a/src/components/Touchable/TouchableHighlight.js b/src/components/Touchable/TouchableHighlight.js index e33561a7..eda0c047 100644 --- a/src/components/Touchable/TouchableHighlight.js +++ b/src/components/Touchable/TouchableHighlight.js @@ -14,7 +14,7 @@ // Note (avik): add @flow when Flow supports spread properties in propTypes -var ColorPropType = require('../../apis/StyleSheet/ColorPropType'); +var ColorPropType = require('../../propTypes/ColorPropType'); var NativeMethodsMixin = require('../../modules/NativeMethodsMixin'); var React = require('react'); var StyleSheet = require('../../apis/StyleSheet'); diff --git a/src/components/Touchable/TouchableWithoutFeedback.js b/src/components/Touchable/TouchableWithoutFeedback.js index 12ae0987..1a8b82c7 100644 --- a/src/components/Touchable/TouchableWithoutFeedback.js +++ b/src/components/Touchable/TouchableWithoutFeedback.js @@ -12,7 +12,7 @@ */ 'use strict'; -var EdgeInsetsPropType = require('../../apis/StyleSheet/EdgeInsetsPropType'); +var EdgeInsetsPropType = require('../../propTypes/EdgeInsetsPropType'); var React = require('react'); var TimerMixin = require('react-timer-mixin'); var Touchable = require('./Touchable'); diff --git a/src/components/View/ViewStylePropTypes.js b/src/components/View/ViewStylePropTypes.js index 93ad847f..72f71a03 100644 --- a/src/components/View/ViewStylePropTypes.js +++ b/src/components/View/ViewStylePropTypes.js @@ -1,8 +1,8 @@ import { PropTypes } from 'react' -import BorderPropTypes from '../../apis/StyleSheet/BorderPropTypes' -import ColorPropType from '../../apis/StyleSheet/ColorPropType' -import LayoutPropTypes from '../../apis/StyleSheet/LayoutPropTypes' -import TransformPropTypes from '../../apis/StyleSheet/TransformPropTypes' +import BorderPropTypes from '../../propTypes/BorderPropTypes' +import ColorPropType from '../../propTypes/ColorPropType' +import LayoutPropTypes from '../../propTypes/LayoutPropTypes' +import TransformPropTypes from '../../propTypes/TransformPropTypes' const { number, oneOf, string } = PropTypes const autoOrHiddenOrVisible = oneOf([ 'auto', 'hidden', 'visible' ]) diff --git a/src/components/View/index.js b/src/components/View/index.js index 63303dff..d17e497e 100644 --- a/src/components/View/index.js +++ b/src/components/View/index.js @@ -3,7 +3,7 @@ import createNativeComponent from '../../modules/createNativeComponent' import normalizeNativeEvent from '../../apis/PanResponder/normalizeNativeEvent' import { Component, PropTypes } from 'react' import StyleSheet from '../../apis/StyleSheet' -import StyleSheetPropType from '../../apis/StyleSheet/StyleSheetPropType' +import StyleSheetPropType from '../../propTypes/StyleSheetPropType' import ViewStylePropTypes from './ViewStylePropTypes' class View extends Component { diff --git a/src/index.js b/src/index.js index 907eb6ab..58ea1276 100644 --- a/src/index.js +++ b/src/index.js @@ -38,9 +38,9 @@ import NativeModules from './modules/NativeModules' // propTypes -import ColorPropType from './apis/StyleSheet/ColorPropType' -import EdgeInsetsPropType from './apis/StyleSheet/EdgeInsetsPropType' -import PointPropType from './apis/StyleSheet/PointPropType' +import ColorPropType from './propTypes/ColorPropType' +import EdgeInsetsPropType from './propTypes/EdgeInsetsPropType' +import PointPropType from './propTypes/PointPropType' const ReactNative = { // top-level API diff --git a/src/apis/StyleSheet/normalizeColor.js b/src/modules/normalizeColor/index.js similarity index 100% rename from src/apis/StyleSheet/normalizeColor.js rename to src/modules/normalizeColor/index.js diff --git a/src/apis/StyleSheet/BorderPropTypes.js b/src/propTypes/BorderPropTypes.js similarity index 92% rename from src/apis/StyleSheet/BorderPropTypes.js rename to src/propTypes/BorderPropTypes.js index a85aa91a..238cc1e5 100644 --- a/src/apis/StyleSheet/BorderPropTypes.js +++ b/src/propTypes/BorderPropTypes.js @@ -1,5 +1,5 @@ import { PropTypes } from 'react' -import ColorPropType from '../../apis/StyleSheet/ColorPropType' +import ColorPropType from './ColorPropType' const numberOrString = PropTypes.oneOfType([ PropTypes.number, PropTypes.string ]) const BorderStylePropType = PropTypes.oneOf([ 'solid', 'dotted', 'dashed' ]) diff --git a/src/apis/StyleSheet/ColorPropType.js b/src/propTypes/ColorPropType.js similarity index 97% rename from src/apis/StyleSheet/ColorPropType.js rename to src/propTypes/ColorPropType.js index 754035bb..83effacc 100644 --- a/src/apis/StyleSheet/ColorPropType.js +++ b/src/propTypes/ColorPropType.js @@ -13,7 +13,7 @@ import { PropTypes } from 'react' import ReactPropTypeLocationNames from 'react/lib/ReactPropTypeLocationNames' -var normalizeColor = require('./normalizeColor'); +var normalizeColor = require('../modules/normalizeColor'); var colorPropType = function(isRequired, props, propName, componentName, location, propFullName) { var color = props[propName]; diff --git a/src/apis/StyleSheet/EdgeInsetsPropType.js b/src/propTypes/EdgeInsetsPropType.js similarity index 100% rename from src/apis/StyleSheet/EdgeInsetsPropType.js rename to src/propTypes/EdgeInsetsPropType.js diff --git a/src/apis/StyleSheet/LayoutPropTypes.js b/src/propTypes/LayoutPropTypes.js similarity index 100% rename from src/apis/StyleSheet/LayoutPropTypes.js rename to src/propTypes/LayoutPropTypes.js diff --git a/src/apis/StyleSheet/PointPropType.js b/src/propTypes/PointPropType.js similarity index 100% rename from src/apis/StyleSheet/PointPropType.js rename to src/propTypes/PointPropType.js diff --git a/src/apis/StyleSheet/StyleSheetPropType.js b/src/propTypes/StyleSheetPropType.js similarity index 92% rename from src/apis/StyleSheet/StyleSheetPropType.js rename to src/propTypes/StyleSheetPropType.js index 8a8d2652..07c7255d 100644 --- a/src/apis/StyleSheet/StyleSheetPropType.js +++ b/src/propTypes/StyleSheetPropType.js @@ -6,7 +6,7 @@ */ import createStrictShapeTypeChecker from './createStrictShapeTypeChecker' -import flattenStyle from './flattenStyle' +import flattenStyle from '../modules/flattenStyle' module.exports = function StyleSheetPropType(shape) { const shapePropType = createStrictShapeTypeChecker(shape) diff --git a/src/propTypes/TransformPropTypes.js b/src/propTypes/TransformPropTypes.js new file mode 100644 index 00000000..023f453f --- /dev/null +++ b/src/propTypes/TransformPropTypes.js @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * @flow + */ + +import { PropTypes } from 'react' + +const { arrayOf, number, oneOfType, shape, string } = PropTypes +const ArrayOfNumberPropType = arrayOf(number) +const numberOrString = oneOfType([ number, string ]) + +const TransformMatrixPropType = function ( + props : Object, + propName : string, + componentName : string +) : ?Error { + if (props.transform && props.transformMatrix) { + return new Error( + 'transformMatrix and transform styles cannot be used on the same ' + + 'component' + ) + } + return ArrayOfNumberPropType(props, propName, componentName) +} + +const TransformPropTypes = { + transform: arrayOf( + oneOfType([ + shape({ perspective: numberOrString }), + shape({ rotate: string }), + shape({ rotateX: string }), + shape({ rotateY: string }), + shape({ rotateZ: string }), + shape({ scale: number }), + shape({ scaleX: number }), + shape({ scaleY: number }), + shape({ skewX: string }), + shape({ skewY: string }), + shape({ translateX: numberOrString }), + shape({ translateY: numberOrString }), + shape({ translateZ: numberOrString }), + shape({ translate3d: string }) + ]) + ), + transformMatrix: TransformMatrixPropType +} + +module.exports = TransformPropTypes diff --git a/src/apis/StyleSheet/createStrictShapeTypeChecker.js b/src/propTypes/createStrictShapeTypeChecker.js similarity index 100% rename from src/apis/StyleSheet/createStrictShapeTypeChecker.js rename to src/propTypes/createStrictShapeTypeChecker.js