Skip to content

Commit 3f62904

Browse files
yungstersfacebook-github-bot
authored andcommitted
RN: Deprecate Prop Types
Summary: Deprecates `prop-types` from React Native. Existing use cases will be presented with a warning to migrate to the newly published `deprecated-react-native-prop-types` module. In a subsequent release, these will be removed from React Native. Changelog: [General][Changed] - Accessing `Image.propTypes`, `Text.propTypes`, `TextInput.propTypes`, `ColorPropType`, `EdgeInsetsPropType`, `PointPropType`, or `ViewPropTypes` now emits a deprecation warning. Reviewed By: kacieb Differential Revision: D29019309 fbshipit-source-id: 21e518e588fa05c498cc75ba81f69cfa8a9d0613
1 parent 1e6add1 commit 3f62904

File tree

8 files changed

+59
-41
lines changed

8 files changed

+59
-41
lines changed

BUCK

+1
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ rn_library(
690690
"//xplat/js:node_modules__abort_19controller",
691691
"//xplat/js:node_modules__anser",
692692
"//xplat/js:node_modules__base64_19js",
693+
"//xplat/js:node_modules__deprecated_19react_19native_19prop_19types",
693694
"//xplat/js:node_modules__event_19target_19shim",
694695
"//xplat/js:node_modules__invariant",
695696
"//xplat/js:node_modules__nullthrows",

Libraries/Components/TextInput/TextInput.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
import * as React from 'react';
1212

13-
import DeprecatedTextInputPropTypes from '../../DeprecatedPropTypes/DeprecatedTextInputPropTypes';
14-
1513
import Platform from '../../Utilities/Platform';
1614
import StyleSheet, {
1715
type TextStyleProp,
@@ -34,7 +32,6 @@ import type {
3432
PressEvent,
3533
} from '../../Types/CoreEventTypes';
3634
import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
37-
import type {TextInputNativeCommands} from './TextInputNativeCommands';
3835

3936
const {useLayoutEffect, useRef, useState} = React;
4037

@@ -1244,8 +1241,11 @@ const ExportedForwardRef: React.AbstractComponent<
12441241
);
12451242
});
12461243

1247-
// TODO: Deprecate this
1248-
ExportedForwardRef.propTypes = DeprecatedTextInputPropTypes;
1244+
/**
1245+
* Switch to `deprecated-react-native-prop-types` for compatibility with future
1246+
* releases. This is deprecated and will be removed in the future.
1247+
*/
1248+
ExportedForwardRef.propTypes = require('deprecated-react-native-prop-types').TextInputPropTypes;
12491249

12501250
// $FlowFixMe[prop-missing]
12511251
ExportedForwardRef.State = {
@@ -1263,7 +1263,6 @@ type TextInputComponentStatics = $ReadOnly<{|
12631263
focusTextInput: typeof TextInputState.focusTextInput,
12641264
blurTextInput: typeof TextInputState.blurTextInput,
12651265
|}>,
1266-
propTypes: typeof DeprecatedTextInputPropTypes,
12671266
|}>;
12681267

12691268
const styles = StyleSheet.create({

Libraries/Image/Image.android.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* @format
99
*/
1010

11-
import DeprecatedImagePropType from '../DeprecatedPropTypes/DeprecatedImagePropType';
1211
import ImageViewNativeComponent from './ImageViewNativeComponent';
1312
import * as React from 'react';
1413
import StyleSheet from '../StyleSheet/StyleSheet';
@@ -115,7 +114,6 @@ type ImageComponentStatics = $ReadOnly<{|
115114
abortPrefetch: typeof abortPrefetch,
116115
queryCache: typeof queryCache,
117116
resolveAssetSource: typeof resolveAssetSource,
118-
propTypes: typeof DeprecatedImagePropType,
119117
|}>;
120118

121119
/**
@@ -299,10 +297,11 @@ Image.queryCache = queryCache;
299297
* comment and run Flow. */
300298
Image.resolveAssetSource = resolveAssetSource;
301299

302-
/* $FlowFixMe(>=0.89.0 site=react_native_android_fb) This comment suppresses an
303-
* error found when Flow v0.89 was deployed. To see the error, delete this
304-
* comment and run Flow. */
305-
Image.propTypes = DeprecatedImagePropType;
300+
/**
301+
* Switch to `deprecated-react-native-prop-types` for compatibility with future
302+
* releases. This is deprecated and will be removed in the future.
303+
*/
304+
Image.propTypes = require('deprecated-react-native-prop-types').ImagePropTypes;
306305

307306
const styles = StyleSheet.create({
308307
base: {

Libraries/Image/Image.ios.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* @format
99
*/
1010

11-
import DeprecatedImagePropType from '../DeprecatedPropTypes/DeprecatedImagePropType';
1211
import * as React from 'react';
1312
import StyleSheet from '../StyleSheet/StyleSheet';
1413

@@ -94,7 +93,6 @@ type ImageComponentStatics = $ReadOnly<{|
9493
prefetchWithMetadata: typeof prefetchWithMetadata,
9594
queryCache: typeof queryCache,
9695
resolveAssetSource: typeof resolveAssetSource,
97-
propTypes: typeof DeprecatedImagePropType,
9896
|}>;
9997

10098
/**
@@ -234,7 +232,11 @@ Image.queryCache = queryCache;
234232
* delete this comment and run Flow. */
235233
Image.resolveAssetSource = resolveAssetSource;
236234

237-
Image.propTypes = DeprecatedImagePropType;
235+
/**
236+
* Switch to `deprecated-react-native-prop-types` for compatibility with future
237+
* releases. This is deprecated and will be removed in the future.
238+
*/
239+
Image.propTypes = require('deprecated-react-native-prop-types').ImagePropTypes;
238240

239241
const styles = StyleSheet.create({
240242
base: {

Libraries/Text/Text.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* @format
99
*/
1010

11-
import DeprecatedTextPropTypes from '../DeprecatedPropTypes/DeprecatedTextPropTypes';
1211
import * as PressabilityDebug from '../Pressability/PressabilityDebug';
1312
import usePressability from '../Pressability/usePressability';
1413
import StyleSheet from '../StyleSheet/StyleSheet';
@@ -188,8 +187,11 @@ const Text: React.AbstractComponent<
188187

189188
Text.displayName = 'Text';
190189

191-
// TODO: Delete this.
192-
Text.propTypes = DeprecatedTextPropTypes;
190+
/**
191+
* Switch to `deprecated-react-native-prop-types` for compatibility with future
192+
* releases. This is deprecated and will be removed in the future.
193+
*/
194+
Text.propTypes = require('deprecated-react-native-prop-types').TextPropTypes;
193195

194196
/**
195197
* Returns false until the first time `newValue` is true, after which this will
@@ -204,8 +206,4 @@ function useLazyInitialization(newValue: boolean): boolean {
204206
return oldValue;
205207
}
206208

207-
// $FlowFixMe[incompatible-cast] - No good way to type a React.AbstractComponent with statics.
208-
module.exports = (Text: typeof Text &
209-
$ReadOnly<{
210-
propTypes: typeof DeprecatedTextPropTypes,
211-
}>);
209+
module.exports = Text;

index.js

+25-16
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,6 @@ import typeof RCTDeviceEventEmitter from './Libraries/EventEmitter/RCTDeviceEven
9797
import typeof RCTNativeAppEventEmitter from './Libraries/EventEmitter/RCTNativeAppEventEmitter';
9898
import typeof {RootTagContext} from './Libraries/ReactNative/RootTag';
9999

100-
// Prop Types
101-
import typeof DeprecatedColorPropType from './Libraries/DeprecatedPropTypes/DeprecatedColorPropType';
102-
import typeof DeprecatedEdgeInsetsPropType from './Libraries/DeprecatedPropTypes/DeprecatedEdgeInsetsPropType';
103-
import typeof DeprecatedPointPropType from './Libraries/DeprecatedPropTypes/DeprecatedPointPropType';
104-
import typeof DeprecatedViewPropTypes from './Libraries/DeprecatedPropTypes/DeprecatedViewPropTypes';
105-
106100
import type {HostComponent as _HostComponentInternal} from './Libraries/Renderer/shims/ReactNativeTypes';
107101

108102
export type HostComponent<T> = _HostComponentInternal<T>;
@@ -450,19 +444,34 @@ module.exports = {
450444
'LogBox is enabled by default so there is no need to call unstable_enableLogBox() anymore. This is a no op and will be removed in the next version.',
451445
);
452446
},
453-
// Prop Types
454-
// $FlowFixMe[value-as-type]
455-
get ColorPropType(): DeprecatedColorPropType {
456-
return require('./Libraries/DeprecatedPropTypes/DeprecatedColorPropType');
447+
// Deprecated Prop Types
448+
get ColorPropType(): $FlowFixMe {
449+
console.warn(
450+
'ColorPropType will be removed from React Native. Migrate to ' +
451+
"ColorPropType exported from 'deprecated-react-native-prop-types'.",
452+
);
453+
return require('deprecated-react-native-prop-types').ColorPropType;
457454
},
458-
get EdgeInsetsPropType(): DeprecatedEdgeInsetsPropType {
459-
return require('./Libraries/DeprecatedPropTypes/DeprecatedEdgeInsetsPropType');
455+
get EdgeInsetsPropType(): $FlowFixMe {
456+
console.warn(
457+
'EdgeInsetsPropType will be removed from React Native. Migrate to ' +
458+
"EdgeInsetsPropType exported from 'deprecated-react-native-prop-types'.",
459+
);
460+
return require('deprecated-react-native-prop-types').EdgeInsetsPropType;
460461
},
461-
get PointPropType(): DeprecatedPointPropType {
462-
return require('./Libraries/DeprecatedPropTypes/DeprecatedPointPropType');
462+
get PointPropType(): $FlowFixMe {
463+
console.warn(
464+
'PointPropType will be removed from React Native. Migrate to ' +
465+
"PointPropType exported from 'deprecated-react-native-prop-types'.",
466+
);
467+
return require('deprecated-react-native-prop-types').PointPropType;
463468
},
464-
get ViewPropTypes(): DeprecatedViewPropTypes {
465-
return require('./Libraries/DeprecatedPropTypes/DeprecatedViewPropTypes');
469+
get ViewPropTypes(): $FlowFixMe {
470+
console.warn(
471+
'ViewPropTypes will be removed from React Native. Migrate to ' +
472+
"ViewPropTypes exported from 'deprecated-react-native-prop-types'.",
473+
);
474+
return require('deprecated-react-native-prop-types').ViewPropTypes;
466475
},
467476
};
468477

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"anser": "^1.4.9",
100100
"base64-js": "^1.1.2",
101101
"event-target-shim": "^5.0.1",
102+
"deprecated-react-native-prop-types": "^2.1.0",
102103
"hermes-engine": "~0.9.0",
103104
"invariant": "^2.2.4",
104105
"jsc-android": "^250230.2.1",

yarn.lock

+11-2
Original file line numberDiff line numberDiff line change
@@ -2350,6 +2350,15 @@ depd@~1.1.2:
23502350
resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9"
23512351
integrity sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=
23522352

2353+
deprecated-react-native-prop-types@^2.1.0:
2354+
version "2.1.0"
2355+
resolved "https://registry.yarnpkg.com/deprecated-react-native-prop-types/-/deprecated-react-native-prop-types-2.1.0.tgz#1f71cc06951131dc6b968c352047bfdab9d478b2"
2356+
integrity sha512-VZZzU9V6hHxinVI4Ca7imJyXkCcJoRD1GTomQMZt+wcbx0iY22lqFXcJvpWVEoAz01+vhbuWt5Sc3tzrXhRZYw==
2357+
dependencies:
2358+
"@react-native/normalize-color" "*"
2359+
invariant "*"
2360+
prop-types "*"
2361+
23532362
destroy@~1.0.4:
23542363
version "1.0.4"
23552364
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80"
@@ -3438,7 +3447,7 @@ interpret@^1.0.0:
34383447
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.1.0.tgz#7ed1b1410c6a0e0f78cf95d3b8440c63f78b8614"
34393448
integrity sha1-ftGxQQxqDg94z5XTuEQMY/eLhhQ=
34403449

3441-
invariant@^2.2.4:
3450+
invariant@*, invariant@^2.2.4:
34423451
version "2.2.4"
34433452
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
34443453
integrity sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==
@@ -5504,7 +5513,7 @@ prompts@^2.0.1, prompts@^2.4.0:
55045513
kleur "^3.0.3"
55055514
sisteransi "^1.0.5"
55065515

5507-
prop-types@^15.7.2:
5516+
prop-types@*, prop-types@^15.7.2:
55085517
version "15.7.2"
55095518
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
55105519
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==

0 commit comments

Comments
 (0)