Skip to content

Commit

Permalink
Move ImageSourcePropType.js, ImageStylePropTypes.js, TextPropTypes.js (
Browse files Browse the repository at this point in the history
…facebook#21387)

Summary:
related facebook#21342

TODO
* move ImageSourcePropType.js, ImageStylePropTypes.js, TextPropTypes.js
* fix flow error

CheckList
 - [x] `yarn prettier`
 - [x] `yarn flow-check-android`
 - [x] `yarn flow-check-ios`

All flow checks pass.

[GENERAL] [ENHANCEMENT] [DeprecatedImageSourcePropType.js] - Created.
[GENERAL] [ENHANCEMENT] [DeprecatedImageStylePropTypes.js] - Created.
[GENERAL] [ENHANCEMENT] [DeprecatedTextPropTypes.js] - Created.
Pull Request resolved: facebook#21387

Reviewed By: TheSavior

Differential Revision: D10099753

Pulled By: RSNara

fbshipit-source-id: c907af6d1549ee42de1a2e17f278998e8422110f
  • Loading branch information
nissy-dev authored and facebook-github-bot committed Sep 29, 2018
1 parent 6422883 commit 91f9878
Show file tree
Hide file tree
Showing 11 changed files with 278 additions and 113 deletions.
4 changes: 2 additions & 2 deletions Libraries/Components/View/ReactNativeStyleAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

const ImageStylePropTypes = require('ImageStylePropTypes');
const DeprecatedImageStylePropTypes = require('DeprecatedImageStylePropTypes');
const TextStylePropTypes = require('TextStylePropTypes');
const ViewStylePropTypes = require('ViewStylePropTypes');

Expand All @@ -23,7 +23,7 @@ const ReactNativeStyleAttributes = {};
for (const attributeName of Object.keys({
...ViewStylePropTypes,
...TextStylePropTypes,
...ImageStylePropTypes,
...DeprecatedImageStylePropTypes,
})) {
ReactNativeStyleAttributes[attributeName] = true;
}
Expand Down
39 changes: 39 additions & 0 deletions Libraries/DeprecatedPropTypes/DeprecatedImageSourcePropType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* 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.
*
* @no-flow
* @format
*/
'use strict';

const PropTypes = require('prop-types');

const ImageURISourcePropType = PropTypes.shape({
uri: PropTypes.string,
bundle: PropTypes.string,
method: PropTypes.string,
headers: PropTypes.objectOf(PropTypes.string),
body: PropTypes.string,
cache: PropTypes.oneOf([
'default',
'reload',
'force-cache',
'only-if-cached',
]),
width: PropTypes.number,
height: PropTypes.number,
scale: PropTypes.number,
});

const ImageSourcePropType = PropTypes.oneOfType([
ImageURISourcePropType,
// Opaque type returned by require('./image.jpg')
PropTypes.number,
// Multiple sources
PropTypes.arrayOf(ImageURISourcePropType),
]);

module.exports = ImageSourcePropType;
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
'use strict';

const DeprecatedColorPropType = require('DeprecatedColorPropType');
const LayoutPropTypes = require('LayoutPropTypes');
const ReactPropTypes = require('prop-types');
const DeprecatedShadowPropTypesIOS = require('DeprecatedShadowPropTypesIOS');
const DeprecatedTransformPropTypes = require('DeprecatedTransformPropTypes');
const LayoutPropTypes = require('LayoutPropTypes');
const ReactPropTypes = require('prop-types');

const ImageStylePropTypes = {
...LayoutPropTypes,
Expand Down
41 changes: 41 additions & 0 deletions Libraries/DeprecatedPropTypes/DeprecatedTextPropTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* 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.
*
* @flow
* @format
*/

'use strict';

const DeprecatedColorPropType = require('DeprecatedColorPropType');
const DeprecatedEdgeInsetsPropType = require('DeprecatedEdgeInsetsPropType');
const PropTypes = require('prop-types');
const StyleSheetPropType = require('DeprecatedStyleSheetPropType');
const TextStylePropTypes = require('TextStylePropTypes');

const stylePropType = StyleSheetPropType(TextStylePropTypes);

module.exports = {
ellipsizeMode: PropTypes.oneOf(['head', 'middle', 'tail', 'clip']),
numberOfLines: PropTypes.number,
textBreakStrategy: PropTypes.oneOf(['simple', 'highQuality', 'balanced']),
onLayout: PropTypes.func,
onPress: PropTypes.func,
onLongPress: PropTypes.func,
pressRetentionOffset: DeprecatedEdgeInsetsPropType,
selectable: PropTypes.bool,
selectionColor: DeprecatedColorPropType,
suppressHighlighting: PropTypes.bool,
style: stylePropType,
testID: PropTypes.string,
nativeID: PropTypes.string,
allowFontScaling: PropTypes.bool,
maxFontSizeMultiplier: PropTypes.number,
accessible: PropTypes.bool,
adjustsFontSizeToFit: PropTypes.bool,
minimumFontScale: PropTypes.number,
disabled: PropTypes.bool,
};
8 changes: 4 additions & 4 deletions Libraries/Image/Image.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

'use strict';

const DeprecatedImageStylePropTypes = require('DeprecatedImageStylePropTypes');
const DeprecatedStyleSheetPropType = require('DeprecatedStyleSheetPropType');
const DeprecatedViewPropTypes = require('DeprecatedViewPropTypes');
const ImageStylePropTypes = require('ImageStylePropTypes');
const ImageViewNativeComponent = require('ImageViewNativeComponent');
const NativeModules = require('NativeModules');
const PropTypes = require('prop-types');
const React = require('React');
const ReactNative = require('ReactNative');
const StyleSheet = require('StyleSheet');
const DeprecatedStyleSheetPropType = require('DeprecatedStyleSheetPropType');
const ImageViewNativeComponent = require('ImageViewNativeComponent');
const TextAncestor = require('TextAncestor');

const flattenStyle = require('flattenStyle');
Expand All @@ -38,7 +38,7 @@ function generateRequestId() {

const ImageProps = {
...DeprecatedViewPropTypes,
style: DeprecatedStyleSheetPropType(ImageStylePropTypes),
style: DeprecatedStyleSheetPropType(DeprecatedImageStylePropTypes),
/**
* See https://facebook.github.io/react-native/docs/image.html#source
*/
Expand Down
18 changes: 9 additions & 9 deletions Libraries/Image/ImageProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
'use strict';

const DeprecatedEdgeInsetsPropType = require('DeprecatedEdgeInsetsPropType');
const ImageSourcePropType = require('ImageSourcePropType');
const ImageStylePropTypes = require('ImageStylePropTypes');
const PropTypes = require('prop-types');
const DeprecatedImageSourcePropType = require('DeprecatedImageSourcePropType');
const DeprecatedImageStylePropTypes = require('DeprecatedImageStylePropTypes');
const DeprecatedStyleSheetPropType = require('DeprecatedStyleSheetPropType');
const PropTypes = require('prop-types');

import type {DimensionValue} from 'StyleSheetTypes';
import type {ViewProps} from 'ViewPropTypes';
import type {ImageSource} from 'ImageSource';
import type {EdgeInsetsProp} from 'EdgeInsetsPropType';
import type {SyntheticEvent} from 'CoreEventTypes';
import type {EdgeInsetsProp} from 'EdgeInsetsPropType';
import type {ImageSource} from 'ImageSource';
import type {ViewStyleProp, ImageStyleProp} from 'StyleSheet';
import type {DimensionValue} from 'StyleSheetTypes';
import type {ViewProps} from 'ViewPropTypes';

type OnLoadEvent = SyntheticEvent<
$ReadOnly<{|
Expand Down Expand Up @@ -78,13 +78,13 @@ module.exports = {
/**
* See https://facebook.github.io/react-native/docs/image.html#style
*/
style: DeprecatedStyleSheetPropType(ImageStylePropTypes),
style: DeprecatedStyleSheetPropType(DeprecatedImageStylePropTypes),
/**
* The image source (either a remote URL or a local file resource).
*
* See https://facebook.github.io/react-native/docs/image.html#source
*/
source: ImageSourcePropType,
source: DeprecatedImageSourcePropType,
/**
* A static image to display while loading the image source.
*
Expand Down
58 changes: 58 additions & 0 deletions Libraries/Image/ImageSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,72 @@
// instances of classes like FBIcon.
// https://fburl.com/8lynhvtw
export type ImageURISource = $ReadOnly<{
/**
* `uri` is a string representing the resource identifier for the image, which
* could be an http address, a local file path, or the name of a static image
* resource (which should be wrapped in the `require('./path/to/image.png')`
* function).
*/
uri?: ?string,

/**
* `bundle` is the iOS asset bundle which the image is included in. This
* will default to [NSBundle mainBundle] if not set.
* @platform ios
*/
bundle?: ?string,

/**
* `method` is the HTTP Method to use. Defaults to GET if not specified.
*/
method?: ?string,

/**
* `headers` is an object representing the HTTP headers to send along with the
* request for a remote image.
*/
headers?: ?Object,

/**
* `body` is the HTTP body to send with the request. This must be a valid
* UTF-8 string, and will be sent exactly as specified, with no
* additional encoding (e.g. URL-escaping or base64) applied.
*/
body?: ?string,

/**
* `cache` determines how the requests handles potentially cached
* responses.
*
* - `default`: Use the native platforms default strategy. `useProtocolCachePolicy` on iOS.
*
* - `reload`: The data for the URL will be loaded from the originating source.
* No existing cache data should be used to satisfy a URL load request.
*
* - `force-cache`: The existing cached data will be used to satisfy the request,
* regardless of its age or expiration date. If there is no existing data in the cache
* corresponding the request, the data is loaded from the originating source.
*
* - `only-if-cached`: The existing cache data will be used to satisfy a request, regardless of
* its age or expiration date. If there is no existing data in the cache corresponding
* to a URL load request, no attempt is made to load the data from the originating source,
* and the load is considered to have failed.
*
* @platform ios
*/
cache?: ?('default' | 'reload' | 'force-cache' | 'only-if-cached'),

/**
* `width` and `height` can be specified if known at build time, in which case
* these will be used to set the default `<Image/>` component dimensions.
*/
width?: ?number,
height?: ?number,

/**
* `scale` is used to indicate the scale factor of the image. Defaults to 1.0 if
* unspecified, meaning that one image pixel equates to one display point / DIP.
*/
scale?: ?number,
}>;

Expand Down
90 changes: 0 additions & 90 deletions Libraries/Image/ImageSourcePropType.js

This file was deleted.

4 changes: 2 additions & 2 deletions Libraries/StyleSheet/StyleSheetValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

const ImageStylePropTypes = require('ImageStylePropTypes');
const DeprecatedImageStylePropTypes = require('DeprecatedImageStylePropTypes');
const TextStylePropTypes = require('TextStylePropTypes');
const ViewStylePropTypes = require('ViewStylePropTypes');

Expand Down Expand Up @@ -85,7 +85,7 @@ const styleError = function(message1, style, caller?, message2?) {
const allStylePropTypes = {};

if (__DEV__ && !global.__RCTProfileIsProfiling) {
StyleSheetValidation.addValidStylePropTypes(ImageStylePropTypes);
StyleSheetValidation.addValidStylePropTypes(DeprecatedImageStylePropTypes);
StyleSheetValidation.addValidStylePropTypes(TextStylePropTypes);
StyleSheetValidation.addValidStylePropTypes(ViewStylePropTypes);
}
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Text/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

'use strict';

const DeprecatedTextPropTypes = require('DeprecatedTextPropTypes');
const React = require('React');
const ReactNativeViewAttributes = require('ReactNativeViewAttributes');
const TextAncestor = require('TextAncestor');
const TextPropTypes = require('TextPropTypes');
const Touchable = require('Touchable');
const UIManager = require('UIManager');

Expand Down Expand Up @@ -279,6 +279,6 @@ const Text = (
const TextToExport = React.forwardRef(Text);

// TODO: Deprecate this.
TextToExport.propTypes = TextPropTypes;
TextToExport.propTypes = DeprecatedTextPropTypes;

module.exports = (TextToExport: Class<NativeComponent<TextProps>>);
Loading

0 comments on commit 91f9878

Please sign in to comment.