Skip to content

Commit ef3db66

Browse files
Brian Vaughnfacebook-github-bot
Brian Vaughn
authored andcommitted
Added deprecation warning for View.* static accessibility traits accessors
Reviewed By: spicyj Differential Revision: D4749932 fbshipit-source-id: 5f07200e953f589f939196a161a1bc796c553868
1 parent 5eb954f commit ef3db66

File tree

3 files changed

+76
-20
lines changed

3 files changed

+76
-20
lines changed

Examples/UIExplorer/js/TouchableExample.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ var {
3737
View,
3838
} = ReactNative;
3939

40+
const NativeModules = require('NativeModules');
41+
42+
const forceTouchAvailable = (NativeModules.PlatformConstants &&
43+
NativeModules.PlatformConstants.forceTouchAvailable) || false;
44+
4045
exports.displayName = (undefined: ?string);
4146
exports.description = 'Touchable and onPress examples.';
4247
exports.title = '<Touchable*> and onPress';
@@ -263,7 +268,7 @@ class ForceTouchExample extends React.Component {
263268
};
264269

265270
_renderConsoleText = () => {
266-
return View.forceTouchAvailable ?
271+
return forceTouchAvailable ?
267272
'Force: ' + this.state.force.toFixed(3) :
268273
'3D Touch is not available on this device';
269274
};

Libraries/Components/Touchable/TouchableWithoutFeedback.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ const EdgeInsetsPropType = require('EdgeInsetsPropType');
1515
const React = require('React');
1616
const TimerMixin = require('react-timer-mixin');
1717
const Touchable = require('Touchable');
18-
const View = require('View');
1918

2019
const ensurePositiveDelayProps = require('ensurePositiveDelayProps');
2120
const warning = require('fbjs/lib/warning');
2221

22+
const {
23+
AccessibilityComponentTypes,
24+
AccessibilityTraits,
25+
} = require('ViewAccessibility');
26+
2327
type Event = Object;
2428

2529
const PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};
@@ -37,10 +41,12 @@ const TouchableWithoutFeedback = React.createClass({
3741

3842
propTypes: {
3943
accessible: React.PropTypes.bool,
40-
accessibilityComponentType: React.PropTypes.oneOf(View.AccessibilityComponentType),
44+
accessibilityComponentType: React.PropTypes.oneOf(
45+
AccessibilityComponentTypes
46+
),
4147
accessibilityTraits: React.PropTypes.oneOfType([
42-
React.PropTypes.oneOf(View.AccessibilityTraits),
43-
React.PropTypes.arrayOf(React.PropTypes.oneOf(View.AccessibilityTraits)),
48+
React.PropTypes.oneOf(AccessibilityTraits),
49+
React.PropTypes.arrayOf(React.PropTypes.oneOf(AccessibilityTraits)),
4450
]),
4551
/**
4652
* If true, disable all interactions for this component.

Libraries/Components/View/View.js

+60-15
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const StyleSheetPropType = require('StyleSheetPropType');
2323
const ViewStylePropTypes = require('ViewStylePropTypes');
2424

2525
const invariant = require('fbjs/lib/invariant');
26+
const warning = require('fbjs/lib/warning');
2627

2728
const {
2829
AccessibilityComponentTypes,
@@ -43,16 +44,6 @@ const stylePropType = StyleSheetPropType(ViewStylePropTypes);
4344
const forceTouchAvailable = (NativeModules.PlatformConstants &&
4445
NativeModules.PlatformConstants.forceTouchAvailable) || false;
4546

46-
const statics = {
47-
AccessibilityTraits,
48-
AccessibilityComponentType: AccessibilityComponentTypes,
49-
/**
50-
* Is 3D Touch / Force Touch available (i.e. will touch events include `force`)
51-
* @platform ios
52-
*/
53-
forceTouchAvailable,
54-
};
55-
5647
/**
5748
* The most fundamental component for building a UI, `View` is a container that supports layout with
5849
* [flexbox](docs/flexbox.html), [style](docs/style.html),
@@ -116,10 +107,6 @@ const View = React.createClass({
116107
validAttributes: ReactNativeViewAttributes.RCTView
117108
},
118109

119-
statics: {
120-
...statics,
121-
},
122-
123110
// TODO (bvaughn) Replace this with a deprecated getter warning. This object
124111
// should be accessible via a separate import. It will not be available in
125112
// production mode in the future and so should not be directly accessed.
@@ -520,6 +507,63 @@ const View = React.createClass({
520507
},
521508
});
522509

510+
// Warn about unsupported use of View static properties as these will no longer
511+
// be supported with React fiber. This warning message will go away in the next
512+
// ReactNative release. Use defineProperty() rather than createClass() statics
513+
// because the mixin process auto-triggers the 1-time warning message.
514+
// TODO (bvaughn) Remove these warning messages after the April ReactNative tag.
515+
function mixinStatics (target) {
516+
let warnedAboutAccessibilityTraits = false;
517+
let warnedAboutAccessibilityComponentType = false;
518+
let warnedAboutForceTouchAvailable = false;
519+
520+
// $FlowFixMe https://github.com/facebook/flow/issues/285
521+
Object.defineProperty(target, 'AccessibilityTraits', {
522+
get: function() {
523+
if (!warnedAboutAccessibilityTraits) {
524+
warnedAboutAccessibilityTraits = true;
525+
warning(
526+
false,
527+
'View.AccessibilityTraits has been deprecated and will be ' +
528+
'removed in a future version of ReactNative. Use ' +
529+
'ViewAccessibility.AccessibilityTraits instead.'
530+
);
531+
}
532+
return AccessibilityTraits;
533+
}
534+
});
535+
// $FlowFixMe https://github.com/facebook/flow/issues/285
536+
Object.defineProperty(target, 'AccessibilityComponentType', {
537+
get: function() {
538+
if (!warnedAboutAccessibilityComponentType) {
539+
warnedAboutAccessibilityComponentType = true;
540+
warning(
541+
false,
542+
'View.AccessibilityComponentType has been deprecated and will be ' +
543+
'removed in a future version of ReactNative. Use ' +
544+
'ViewAccessibility.AccessibilityComponentTypes instead.'
545+
);
546+
}
547+
return AccessibilityComponentTypes;
548+
}
549+
});
550+
// $FlowFixMe https://github.com/facebook/flow/issues/285
551+
Object.defineProperty(target, 'forceTouchAvailable', {
552+
get: function() {
553+
if (!warnedAboutForceTouchAvailable) {
554+
warnedAboutForceTouchAvailable = true;
555+
warning(
556+
false,
557+
'View.forceTouchAvailable has been deprecated and will be removed ' +
558+
'in a future version of ReactNative. Use ' +
559+
'NativeModules.PlatformConstants.forceTouchAvailable instead.'
560+
);
561+
}
562+
return forceTouchAvailable;
563+
}
564+
});
565+
}
566+
523567
const RCTView = requireNativeComponent('RCTView', View, {
524568
nativeOnly: {
525569
nativeBackgroundAndroid: true,
@@ -548,10 +592,11 @@ if (
548592
__DEV__ ||
549593
ReactNativeFeatureFlags.useFiber
550594
) {
595+
mixinStatics(View);
551596
ViewToExport = View;
552597
} else {
553598
// TODO (bvaughn) Remove this mixin once all static View accessors are gone.
554-
Object.assign((RCTView : any), statics);
599+
mixinStatics((RCTView : any));
555600
}
556601

557602
// TODO (bvaughn) Temporarily mask Flow warnings for View property accesses.

0 commit comments

Comments
 (0)