Added deprecation warning for View.* static accessibility traits accessors
Reviewed By: spicyj Differential Revision: D4749932 fbshipit-source-id: 5f07200e953f589f939196a161a1bc796c553868
This commit is contained in:
parent
5eb954f660
commit
ef3db66bb1
|
@ -37,6 +37,11 @@ var {
|
|||
View,
|
||||
} = ReactNative;
|
||||
|
||||
const NativeModules = require('NativeModules');
|
||||
|
||||
const forceTouchAvailable = (NativeModules.PlatformConstants &&
|
||||
NativeModules.PlatformConstants.forceTouchAvailable) || false;
|
||||
|
||||
exports.displayName = (undefined: ?string);
|
||||
exports.description = 'Touchable and onPress examples.';
|
||||
exports.title = '<Touchable*> and onPress';
|
||||
|
@ -263,7 +268,7 @@ class ForceTouchExample extends React.Component {
|
|||
};
|
||||
|
||||
_renderConsoleText = () => {
|
||||
return View.forceTouchAvailable ?
|
||||
return forceTouchAvailable ?
|
||||
'Force: ' + this.state.force.toFixed(3) :
|
||||
'3D Touch is not available on this device';
|
||||
};
|
||||
|
|
|
@ -15,11 +15,15 @@ const EdgeInsetsPropType = require('EdgeInsetsPropType');
|
|||
const React = require('React');
|
||||
const TimerMixin = require('react-timer-mixin');
|
||||
const Touchable = require('Touchable');
|
||||
const View = require('View');
|
||||
|
||||
const ensurePositiveDelayProps = require('ensurePositiveDelayProps');
|
||||
const warning = require('fbjs/lib/warning');
|
||||
|
||||
const {
|
||||
AccessibilityComponentTypes,
|
||||
AccessibilityTraits,
|
||||
} = require('ViewAccessibility');
|
||||
|
||||
type Event = Object;
|
||||
|
||||
const PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};
|
||||
|
@ -37,10 +41,12 @@ const TouchableWithoutFeedback = React.createClass({
|
|||
|
||||
propTypes: {
|
||||
accessible: React.PropTypes.bool,
|
||||
accessibilityComponentType: React.PropTypes.oneOf(View.AccessibilityComponentType),
|
||||
accessibilityComponentType: React.PropTypes.oneOf(
|
||||
AccessibilityComponentTypes
|
||||
),
|
||||
accessibilityTraits: React.PropTypes.oneOfType([
|
||||
React.PropTypes.oneOf(View.AccessibilityTraits),
|
||||
React.PropTypes.arrayOf(React.PropTypes.oneOf(View.AccessibilityTraits)),
|
||||
React.PropTypes.oneOf(AccessibilityTraits),
|
||||
React.PropTypes.arrayOf(React.PropTypes.oneOf(AccessibilityTraits)),
|
||||
]),
|
||||
/**
|
||||
* If true, disable all interactions for this component.
|
||||
|
|
|
@ -23,6 +23,7 @@ const StyleSheetPropType = require('StyleSheetPropType');
|
|||
const ViewStylePropTypes = require('ViewStylePropTypes');
|
||||
|
||||
const invariant = require('fbjs/lib/invariant');
|
||||
const warning = require('fbjs/lib/warning');
|
||||
|
||||
const {
|
||||
AccessibilityComponentTypes,
|
||||
|
@ -43,16 +44,6 @@ const stylePropType = StyleSheetPropType(ViewStylePropTypes);
|
|||
const forceTouchAvailable = (NativeModules.PlatformConstants &&
|
||||
NativeModules.PlatformConstants.forceTouchAvailable) || false;
|
||||
|
||||
const statics = {
|
||||
AccessibilityTraits,
|
||||
AccessibilityComponentType: AccessibilityComponentTypes,
|
||||
/**
|
||||
* Is 3D Touch / Force Touch available (i.e. will touch events include `force`)
|
||||
* @platform ios
|
||||
*/
|
||||
forceTouchAvailable,
|
||||
};
|
||||
|
||||
/**
|
||||
* The most fundamental component for building a UI, `View` is a container that supports layout with
|
||||
* [flexbox](docs/flexbox.html), [style](docs/style.html),
|
||||
|
@ -116,10 +107,6 @@ const View = React.createClass({
|
|||
validAttributes: ReactNativeViewAttributes.RCTView
|
||||
},
|
||||
|
||||
statics: {
|
||||
...statics,
|
||||
},
|
||||
|
||||
// TODO (bvaughn) Replace this with a deprecated getter warning. This object
|
||||
// should be accessible via a separate import. It will not be available in
|
||||
// production mode in the future and so should not be directly accessed.
|
||||
|
@ -520,6 +507,63 @@ const View = React.createClass({
|
|||
},
|
||||
});
|
||||
|
||||
// Warn about unsupported use of View static properties as these will no longer
|
||||
// be supported with React fiber. This warning message will go away in the next
|
||||
// ReactNative release. Use defineProperty() rather than createClass() statics
|
||||
// because the mixin process auto-triggers the 1-time warning message.
|
||||
// TODO (bvaughn) Remove these warning messages after the April ReactNative tag.
|
||||
function mixinStatics (target) {
|
||||
let warnedAboutAccessibilityTraits = false;
|
||||
let warnedAboutAccessibilityComponentType = false;
|
||||
let warnedAboutForceTouchAvailable = false;
|
||||
|
||||
// $FlowFixMe https://github.com/facebook/flow/issues/285
|
||||
Object.defineProperty(target, 'AccessibilityTraits', {
|
||||
get: function() {
|
||||
if (!warnedAboutAccessibilityTraits) {
|
||||
warnedAboutAccessibilityTraits = true;
|
||||
warning(
|
||||
false,
|
||||
'View.AccessibilityTraits has been deprecated and will be ' +
|
||||
'removed in a future version of ReactNative. Use ' +
|
||||
'ViewAccessibility.AccessibilityTraits instead.'
|
||||
);
|
||||
}
|
||||
return AccessibilityTraits;
|
||||
}
|
||||
});
|
||||
// $FlowFixMe https://github.com/facebook/flow/issues/285
|
||||
Object.defineProperty(target, 'AccessibilityComponentType', {
|
||||
get: function() {
|
||||
if (!warnedAboutAccessibilityComponentType) {
|
||||
warnedAboutAccessibilityComponentType = true;
|
||||
warning(
|
||||
false,
|
||||
'View.AccessibilityComponentType has been deprecated and will be ' +
|
||||
'removed in a future version of ReactNative. Use ' +
|
||||
'ViewAccessibility.AccessibilityComponentTypes instead.'
|
||||
);
|
||||
}
|
||||
return AccessibilityComponentTypes;
|
||||
}
|
||||
});
|
||||
// $FlowFixMe https://github.com/facebook/flow/issues/285
|
||||
Object.defineProperty(target, 'forceTouchAvailable', {
|
||||
get: function() {
|
||||
if (!warnedAboutForceTouchAvailable) {
|
||||
warnedAboutForceTouchAvailable = true;
|
||||
warning(
|
||||
false,
|
||||
'View.forceTouchAvailable has been deprecated and will be removed ' +
|
||||
'in a future version of ReactNative. Use ' +
|
||||
'NativeModules.PlatformConstants.forceTouchAvailable instead.'
|
||||
);
|
||||
}
|
||||
return forceTouchAvailable;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const RCTView = requireNativeComponent('RCTView', View, {
|
||||
nativeOnly: {
|
||||
nativeBackgroundAndroid: true,
|
||||
|
@ -548,10 +592,11 @@ if (
|
|||
__DEV__ ||
|
||||
ReactNativeFeatureFlags.useFiber
|
||||
) {
|
||||
mixinStatics(View);
|
||||
ViewToExport = View;
|
||||
} else {
|
||||
// TODO (bvaughn) Remove this mixin once all static View accessors are gone.
|
||||
Object.assign((RCTView : any), statics);
|
||||
mixinStatics((RCTView : any));
|
||||
}
|
||||
|
||||
// TODO (bvaughn) Temporarily mask Flow warnings for View property accesses.
|
||||
|
|
Loading…
Reference in New Issue