From efefae92cabc9a09021189e4b56d03819ff30c8b Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Fri, 11 Jun 2021 23:51:00 -0700 Subject: [PATCH] RN: Move `{ => Deprecated}ImageProp{s => Types}` (Android) Summary: Moves `ImagePropTypes` out of `Image.android.js` in preparation for some cleanup. Changelog: [Internal] Reviewed By: TheSavior Differential Revision: D29017076 fbshipit-source-id: e7d3d6533f69dc2c54e7c25e215648d7c7ff1840 --- .../DeprecatedImagePropType.android.js | 131 ++++++++++++++++++ ...Type.js => DeprecatedImagePropType.ios.js} | 0 Libraries/Image/Image.android.js | 122 +--------------- 3 files changed, 134 insertions(+), 119 deletions(-) create mode 100644 Libraries/DeprecatedPropTypes/DeprecatedImagePropType.android.js rename Libraries/DeprecatedPropTypes/{DeprecatedImagePropType.js => DeprecatedImagePropType.ios.js} (100%) diff --git a/Libraries/DeprecatedPropTypes/DeprecatedImagePropType.android.js b/Libraries/DeprecatedPropTypes/DeprecatedImagePropType.android.js new file mode 100644 index 00000000000..7df9fbf644c --- /dev/null +++ b/Libraries/DeprecatedPropTypes/DeprecatedImagePropType.android.js @@ -0,0 +1,131 @@ +/** + * 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 DeprecatedImageStylePropTypes = require('./DeprecatedImageStylePropTypes'); +const DeprecatedStyleSheetPropType = require('./DeprecatedStyleSheetPropType'); +const DeprecatedViewPropTypes = require('./DeprecatedViewPropTypes'); +const PropTypes = require('prop-types'); + +const DeprecatedImagePropType = { + ...DeprecatedViewPropTypes, + style: (DeprecatedStyleSheetPropType( + DeprecatedImageStylePropTypes, + ): ReactPropsCheckType), + /** + * See https://reactnative.dev/docs/image.html#source + */ + source: (PropTypes.oneOfType([ + PropTypes.shape({ + uri: PropTypes.string, + headers: PropTypes.objectOf(PropTypes.string), + }), + // Opaque type returned by require('./image.jpg') + PropTypes.number, + // Multiple sources + PropTypes.arrayOf( + PropTypes.shape({ + uri: PropTypes.string, + width: PropTypes.number, + height: PropTypes.number, + headers: PropTypes.objectOf(PropTypes.string), + }), + ), + ]): React$PropType$Primitive< + | { + headers?: {[string]: string, ...}, + uri?: string, + ... + } + | number + | Array<{ + headers?: {[string]: string, ...}, + height?: number, + uri?: string, + width?: number, + ... + }>, + >), + /** + * blurRadius: the blur radius of the blur filter added to the image + * + * See https://reactnative.dev/docs/image.html#blurradius + */ + blurRadius: PropTypes.number, + /** + * See https://reactnative.dev/docs/image.html#defaultsource + */ + defaultSource: PropTypes.number, + /** + * See https://reactnative.dev/docs/image.html#loadingindicatorsource + */ + loadingIndicatorSource: (PropTypes.oneOfType([ + PropTypes.shape({ + uri: PropTypes.string, + }), + // Opaque type returned by require('./image.jpg') + PropTypes.number, + ]): React$PropType$Primitive<{uri?: string, ...} | number>), + progressiveRenderingEnabled: PropTypes.bool, + fadeDuration: PropTypes.number, + /** + * Analytics Tag used by this Image + */ + internal_analyticTag: PropTypes.string, + /** + * Invoked on load start + */ + onLoadStart: PropTypes.func, + /** + * Invoked on load error + */ + onError: PropTypes.func, + /** + * Invoked when load completes successfully + */ + onLoad: PropTypes.func, + /** + * Invoked when load either succeeds or fails + */ + onLoadEnd: PropTypes.func, + /** + * Used to locate this view in end-to-end tests. + */ + testID: PropTypes.string, + /** + * The mechanism that should be used to resize the image when the image's dimensions + * differ from the image view's dimensions. Defaults to `auto`. + * + * See https://reactnative.dev/docs/image.html#resizemethod + */ + resizeMethod: (PropTypes.oneOf([ + 'auto', + 'resize', + 'scale', + ]): React$PropType$Primitive<'auto' | 'resize' | 'scale'>), + /** + * Determines how to resize the image when the frame doesn't match the raw + * image dimensions. + * + * See https://reactnative.dev/docs/image.html#resizemode + */ + resizeMode: (PropTypes.oneOf([ + 'cover', + 'contain', + 'stretch', + 'repeat', + 'center', + ]): React$PropType$Primitive< + 'cover' | 'contain' | 'stretch' | 'repeat' | 'center', + >), +}; + +module.exports = DeprecatedImagePropType; diff --git a/Libraries/DeprecatedPropTypes/DeprecatedImagePropType.js b/Libraries/DeprecatedPropTypes/DeprecatedImagePropType.ios.js similarity index 100% rename from Libraries/DeprecatedPropTypes/DeprecatedImagePropType.js rename to Libraries/DeprecatedPropTypes/DeprecatedImagePropType.ios.js diff --git a/Libraries/Image/Image.android.js b/Libraries/Image/Image.android.js index 030fa1440d3..81df06415c1 100644 --- a/Libraries/Image/Image.android.js +++ b/Libraries/Image/Image.android.js @@ -8,11 +8,8 @@ * @format */ -import DeprecatedImageStylePropTypes from '../DeprecatedPropTypes/DeprecatedImageStylePropTypes'; -import DeprecatedStyleSheetPropType from '../DeprecatedPropTypes/DeprecatedStyleSheetPropType'; -import DeprecatedViewPropTypes from '../DeprecatedPropTypes/DeprecatedViewPropTypes'; +import DeprecatedImagePropType from '../DeprecatedPropTypes/DeprecatedImagePropType'; import ImageViewNativeComponent from './ImageViewNativeComponent'; -import PropTypes from 'prop-types'; import * as React from 'react'; import StyleSheet from '../StyleSheet/StyleSheet'; import TextAncestor from '../Text/TextAncestor'; @@ -33,119 +30,6 @@ function generateRequestId() { return _requestId++; } -const ImageProps = { - ...DeprecatedViewPropTypes, - style: (DeprecatedStyleSheetPropType( - DeprecatedImageStylePropTypes, - ): ReactPropsCheckType), - /** - * See https://reactnative.dev/docs/image.html#source - */ - source: (PropTypes.oneOfType([ - PropTypes.shape({ - uri: PropTypes.string, - headers: PropTypes.objectOf(PropTypes.string), - }), - // Opaque type returned by require('./image.jpg') - PropTypes.number, - // Multiple sources - PropTypes.arrayOf( - PropTypes.shape({ - uri: PropTypes.string, - width: PropTypes.number, - height: PropTypes.number, - headers: PropTypes.objectOf(PropTypes.string), - }), - ), - ]): React$PropType$Primitive< - | { - headers?: {[string]: string, ...}, - uri?: string, - ... - } - | number - | Array<{ - headers?: {[string]: string, ...}, - height?: number, - uri?: string, - width?: number, - ... - }>, - >), - /** - * blurRadius: the blur radius of the blur filter added to the image - * - * See https://reactnative.dev/docs/image.html#blurradius - */ - blurRadius: PropTypes.number, - /** - * See https://reactnative.dev/docs/image.html#defaultsource - */ - defaultSource: PropTypes.number, - /** - * See https://reactnative.dev/docs/image.html#loadingindicatorsource - */ - loadingIndicatorSource: (PropTypes.oneOfType([ - PropTypes.shape({ - uri: PropTypes.string, - }), - // Opaque type returned by require('./image.jpg') - PropTypes.number, - ]): React$PropType$Primitive<{uri?: string, ...} | number>), - progressiveRenderingEnabled: PropTypes.bool, - fadeDuration: PropTypes.number, - /** - * Analytics Tag used by this Image - */ - internal_analyticTag: PropTypes.string, - /** - * Invoked on load start - */ - onLoadStart: PropTypes.func, - /** - * Invoked on load error - */ - onError: PropTypes.func, - /** - * Invoked when load completes successfully - */ - onLoad: PropTypes.func, - /** - * Invoked when load either succeeds or fails - */ - onLoadEnd: PropTypes.func, - /** - * Used to locate this view in end-to-end tests. - */ - testID: PropTypes.string, - /** - * The mechanism that should be used to resize the image when the image's dimensions - * differ from the image view's dimensions. Defaults to `auto`. - * - * See https://reactnative.dev/docs/image.html#resizemethod - */ - resizeMethod: (PropTypes.oneOf([ - 'auto', - 'resize', - 'scale', - ]): React$PropType$Primitive<'auto' | 'resize' | 'scale'>), - /** - * Determines how to resize the image when the frame doesn't match the raw - * image dimensions. - * - * See https://reactnative.dev/docs/image.html#resizemode - */ - resizeMode: (PropTypes.oneOf([ - 'cover', - 'contain', - 'stretch', - 'repeat', - 'center', - ]): React$PropType$Primitive< - 'cover' | 'contain' | 'stretch' | 'repeat' | 'center', - >), -}; - /** * Retrieve the width and height (in pixels) of an image prior to displaying it * @@ -231,7 +115,7 @@ type ImageComponentStatics = $ReadOnly<{| abortPrefetch: typeof abortPrefetch, queryCache: typeof queryCache, resolveAssetSource: typeof resolveAssetSource, - propTypes: typeof ImageProps, + propTypes: typeof DeprecatedImagePropType, |}>; /** @@ -411,7 +295,7 @@ Image.resolveAssetSource = resolveAssetSource; /* $FlowFixMe(>=0.89.0 site=react_native_android_fb) This comment suppresses an * error found when Flow v0.89 was deployed. To see the error, delete this * comment and run Flow. */ -Image.propTypes = ImageProps; +Image.propTypes = DeprecatedImagePropType; const styles = StyleSheet.create({ base: {