@@ -23,6 +23,7 @@ const StyleSheetPropType = require('StyleSheetPropType');
23
23
const ViewStylePropTypes = require ( 'ViewStylePropTypes' ) ;
24
24
25
25
const invariant = require ( 'fbjs/lib/invariant' ) ;
26
+ const warning = require ( 'fbjs/lib/warning' ) ;
26
27
27
28
const {
28
29
AccessibilityComponentTypes,
@@ -43,16 +44,6 @@ const stylePropType = StyleSheetPropType(ViewStylePropTypes);
43
44
const forceTouchAvailable = ( NativeModules . PlatformConstants &&
44
45
NativeModules . PlatformConstants . forceTouchAvailable ) || false ;
45
46
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
-
56
47
/**
57
48
* The most fundamental component for building a UI, `View` is a container that supports layout with
58
49
* [flexbox](docs/flexbox.html), [style](docs/style.html),
@@ -116,10 +107,6 @@ const View = React.createClass({
116
107
validAttributes : ReactNativeViewAttributes . RCTView
117
108
} ,
118
109
119
- statics : {
120
- ...statics ,
121
- } ,
122
-
123
110
// TODO (bvaughn) Replace this with a deprecated getter warning. This object
124
111
// should be accessible via a separate import. It will not be available in
125
112
// production mode in the future and so should not be directly accessed.
@@ -520,6 +507,63 @@ const View = React.createClass({
520
507
} ,
521
508
} ) ;
522
509
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
+
523
567
const RCTView = requireNativeComponent ( 'RCTView' , View , {
524
568
nativeOnly : {
525
569
nativeBackgroundAndroid : true ,
@@ -548,10 +592,11 @@ if (
548
592
__DEV__ ||
549
593
ReactNativeFeatureFlags . useFiber
550
594
) {
595
+ mixinStatics ( View ) ;
551
596
ViewToExport = View ;
552
597
} else {
553
598
// TODO (bvaughn) Remove this mixin once all static View accessors are gone.
554
- Object . assign ( ( RCTView : any ) , statics ) ;
599
+ mixinStatics ( ( RCTView : any ) ) ;
555
600
}
556
601
557
602
// TODO (bvaughn) Temporarily mask Flow warnings for View property accesses.
0 commit comments