Skip to content

Commit 8dc3ba0

Browse files
yungstersfacebook-github-bot
authored andcommitted
RN: Remove Native Prop Validation
Summary: As we migrate over to static typing solutions for props, we cannot rely on always having `propTypes` available at runtime. This gets us started on that journey by removing the native prop validation that happens when we require native components. bypass-lint Reviewed By: TheSavior Differential Revision: D7976854 fbshipit-source-id: f3ab579a7f0f8cfb716b0eb7fd4625f8168f3d96
1 parent 6c91054 commit 8dc3ba0

File tree

17 files changed

+79
-283
lines changed

17 files changed

+79
-283
lines changed

Libraries/Components/ActivityIndicator/ActivityIndicator.js

+5-15
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
'use strict';
1212

1313
const Platform = require('Platform');
14-
const ProgressBarAndroid = require('ProgressBarAndroid');
1514
const React = require('React');
1615
const StyleSheet = require('StyleSheet');
1716
const View = require('View');
@@ -21,7 +20,10 @@ const requireNativeComponent = require('requireNativeComponent');
2120
import type {NativeComponent} from 'ReactNative';
2221
import type {ViewProps} from 'ViewPropTypes';
2322

24-
let RCTActivityIndicator;
23+
const RCTActivityIndicator =
24+
Platform.OS === 'android'
25+
? require('ProgressBarAndroid')
26+
: requireNativeComponent('RCTActivityIndicatorView');
2527

2628
const GRAY = '#999999';
2729

@@ -98,11 +100,7 @@ const ActivityIndicator = (
98100

99101
return (
100102
<View onLayout={onLayout} style={[styles.container, style]}>
101-
{Platform.OS === 'ios' ? (
102-
<RCTActivityIndicator {...nativeProps} />
103-
) : (
104-
<ProgressBarAndroid {...nativeProps} />
105-
)}
103+
<RCTActivityIndicator {...nativeProps} />
106104
</View>
107105
);
108106
};
@@ -120,14 +118,6 @@ ActivityIndicatorWithRef.defaultProps = {
120118
};
121119
ActivityIndicatorWithRef.displayName = 'ActivityIndicator';
122120

123-
if (Platform.OS === 'ios') {
124-
RCTActivityIndicator = requireNativeComponent(
125-
'RCTActivityIndicatorView',
126-
null,
127-
{nativeOnly: {activityIndicatorViewStyle: true}},
128-
);
129-
}
130-
131121
const styles = StyleSheet.create({
132122
container: {
133123
alignItems: 'center',

Libraries/Components/DatePicker/DatePickerIOS.ios.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const requireNativeComponent = require('requireNativeComponent');
2222

2323
import type {ViewProps} from 'ViewPropTypes';
2424

25+
const RCTDatePickerIOS = requireNativeComponent('RCTDatePicker');
26+
2527
type Event = Object;
2628

2729
type Props = $ReadOnly<{|
@@ -177,6 +179,4 @@ const styles = StyleSheet.create({
177179
},
178180
});
179181

180-
const RCTDatePickerIOS = requireNativeComponent('RCTDatePicker');
181-
182182
module.exports = DatePickerIOS;

Libraries/Components/MaskedView/MaskedViewIOS.ios.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const requireNativeComponent = require('requireNativeComponent');
1717

1818
import type {ViewProps} from 'ViewPropTypes';
1919

20+
const RCTMaskedView = requireNativeComponent('RCTMaskedView');
21+
2022
type Props = {
2123
...ViewProps,
2224

@@ -97,12 +99,4 @@ class MaskedViewIOS extends React.Component<Props> {
9799
}
98100
}
99101

100-
const RCTMaskedView = requireNativeComponent('RCTMaskedView', {
101-
name: 'RCTMaskedView',
102-
displayName: 'RCTMaskedView',
103-
propTypes: {
104-
...ViewPropTypes,
105-
},
106-
});
107-
108102
module.exports = MaskedViewIOS;

Libraries/Components/ProgressViewIOS/ProgressViewIOS.ios.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import type {ImageSource} from 'ImageSource';
2525
import type {ColorValue} from 'StyleSheetTypes';
2626
import type {ViewProps} from 'ViewPropTypes';
2727

28+
const RCTProgressView = requireNativeComponent('RCTProgressView');
29+
2830
type Props = $ReadOnly<{|
2931
...ViewProps,
3032
progressViewStyle?: ?('default' | 'bar'),
@@ -91,11 +93,6 @@ const styles = StyleSheet.create({
9193
},
9294
});
9395

94-
const RCTProgressView = requireNativeComponent(
95-
'RCTProgressView',
96-
ProgressViewIOS,
97-
);
98-
9996
module.exports = ((ProgressViewIOS: any): Class<
10097
ReactNative.NativeComponent<Props>,
10198
>);

Libraries/Components/SafeAreaView/SafeAreaView.ios.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const requireNativeComponent = require('requireNativeComponent');
1414

1515
import type {ViewProps} from 'ViewPropTypes';
1616

17+
const RCTSafeAreaView = requireNativeComponent('RCTSafeAreaView');
18+
1719
type Props = ViewProps & {
1820
children: any,
1921
};
@@ -34,12 +36,4 @@ class SafeAreaView extends React.Component<Props> {
3436
}
3537
}
3638

37-
const RCTSafeAreaView = requireNativeComponent('RCTSafeAreaView', {
38-
name: 'RCTSafeAreaView',
39-
displayName: 'RCTSafeAreaView',
40-
propTypes: {
41-
...ViewPropTypes,
42-
},
43-
});
44-
4539
module.exports = SafeAreaView;

Libraries/Components/ScrollView/ScrollView.js

+22-52
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,28 @@ import type {PointProp} from 'PointPropType';
4545

4646
import type {ColorValue} from 'StyleSheetTypes';
4747

48+
let AndroidScrollView;
49+
let AndroidHorizontalScrollContentView;
50+
let AndroidHorizontalScrollView;
51+
let RCTScrollView;
52+
let RCTScrollContentView;
53+
54+
if (Platform.OS === 'android') {
55+
AndroidScrollView = requireNativeComponent('RCTScrollView');
56+
AndroidHorizontalScrollView = requireNativeComponent(
57+
'AndroidHorizontalScrollView',
58+
);
59+
AndroidHorizontalScrollContentView = requireNativeComponent(
60+
'AndroidHorizontalScrollContentView',
61+
);
62+
} else if (Platform.OS === 'ios') {
63+
RCTScrollView = requireNativeComponent('RCTScrollView');
64+
RCTScrollContentView = requireNativeComponent('RCTScrollContentView');
65+
} else {
66+
RCTScrollView = requireNativeComponent('RCTScrollView');
67+
RCTScrollContentView = requireNativeComponent('RCTScrollContentView');
68+
}
69+
4870
type TouchableProps = $ReadOnly<{|
4971
onTouchStart?: (event: PressEvent) => void,
5072
onTouchMove?: (event: PressEvent) => void,
@@ -1074,56 +1096,4 @@ const styles = StyleSheet.create({
10741096
},
10751097
});
10761098

1077-
let nativeOnlyProps,
1078-
AndroidScrollView,
1079-
AndroidHorizontalScrollContentView,
1080-
AndroidHorizontalScrollView,
1081-
RCTScrollView,
1082-
RCTScrollContentView;
1083-
if (Platform.OS === 'android') {
1084-
nativeOnlyProps = {
1085-
nativeOnly: {
1086-
sendMomentumEvents: true,
1087-
},
1088-
};
1089-
AndroidScrollView = requireNativeComponent(
1090-
'RCTScrollView',
1091-
(ScrollView: React.ComponentType<any>),
1092-
nativeOnlyProps,
1093-
);
1094-
AndroidHorizontalScrollView = requireNativeComponent(
1095-
'AndroidHorizontalScrollView',
1096-
(ScrollView: React.ComponentType<any>),
1097-
nativeOnlyProps,
1098-
);
1099-
AndroidHorizontalScrollContentView = requireNativeComponent(
1100-
'AndroidHorizontalScrollContentView',
1101-
);
1102-
} else if (Platform.OS === 'ios') {
1103-
nativeOnlyProps = {
1104-
nativeOnly: {
1105-
onMomentumScrollBegin: true,
1106-
onMomentumScrollEnd: true,
1107-
onScrollBeginDrag: true,
1108-
onScrollEndDrag: true,
1109-
},
1110-
};
1111-
RCTScrollView = requireNativeComponent(
1112-
'RCTScrollView',
1113-
(ScrollView: React.ComponentType<any>),
1114-
nativeOnlyProps,
1115-
);
1116-
RCTScrollContentView = requireNativeComponent('RCTScrollContentView', View);
1117-
} else {
1118-
nativeOnlyProps = {
1119-
nativeOnly: {},
1120-
};
1121-
RCTScrollView = requireNativeComponent(
1122-
'RCTScrollView',
1123-
null,
1124-
nativeOnlyProps,
1125-
);
1126-
RCTScrollContentView = requireNativeComponent('RCTScrollContentView', View);
1127-
}
1128-
11291099
module.exports = TypedScrollView;

Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.ios.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const requireNativeComponent = require('requireNativeComponent');
2222

2323
import type {ViewProps} from 'ViewPropTypes';
2424

25+
const RCTSegmentedControl = requireNativeComponent('RCTSegmentedControl');
26+
2527
type DefaultProps = {
2628
values: $ReadOnlyArray<string>,
2729
enabled: boolean,
@@ -139,11 +141,6 @@ const styles = StyleSheet.create({
139141
},
140142
});
141143

142-
const RCTSegmentedControl = requireNativeComponent(
143-
'RCTSegmentedControl',
144-
SegmentedControlIOS,
145-
);
146-
147144
module.exports = ((SegmentedControlIOS: any): Class<
148145
ReactNative.NativeComponent<Props>,
149146
>);

Libraries/Components/Slider/Slider.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import type {ViewStyleProp} from 'StyleSheet';
2929
import type {ColorValue} from 'StyleSheetTypes';
3030
import type {ViewProps} from 'ViewPropTypes';
3131

32+
const RCTSlider = requireNativeComponent('RCTSlider');
33+
3234
type Event = Object;
3335

3436
type IOSProps = $ReadOnly<{|
@@ -306,14 +308,4 @@ if (Platform.OS === 'ios') {
306308
});
307309
}
308310

309-
let options = {};
310-
if (Platform.OS === 'android') {
311-
options = {
312-
nativeOnly: {
313-
enabled: true,
314-
},
315-
};
316-
}
317-
const RCTSlider = requireNativeComponent('RCTSlider', Slider, options);
318-
319311
module.exports = ((Slider: any): Class<ReactNative.NativeComponent<Props>>);

Libraries/Components/Switch/Switch.js

+6-17
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ const requireNativeComponent = require('requireNativeComponent');
2525
import type {ColorValue} from 'StyleSheetTypes';
2626
import type {ViewProps} from 'ViewPropTypes';
2727

28+
const RCTSwitch =
29+
Platform.OS === 'android'
30+
? requireNativeComponent('AndroidSwitch')
31+
: requireNativeComponent('RCTSwitch');
32+
2833
type DefaultProps = $ReadOnly<{|
2934
value: boolean,
3035
disabled: boolean,
@@ -40,6 +45,7 @@ type Props = $ReadOnly<{|
4045
onTintColor?: ?ColorValue,
4146
thumbTintColor?: ?ColorValue,
4247
|}>;
48+
4349
/**
4450
* Renders a boolean input.
4551
*
@@ -158,21 +164,4 @@ const styles = StyleSheet.create({
158164
},
159165
});
160166

161-
if (Platform.OS === 'android') {
162-
var RCTSwitch = requireNativeComponent('AndroidSwitch', Switch, {
163-
nativeOnly: {
164-
onChange: true,
165-
on: true,
166-
enabled: true,
167-
trackTintColor: true,
168-
},
169-
});
170-
} else {
171-
var RCTSwitch = requireNativeComponent('RCTSwitch', Switch, {
172-
nativeOnly: {
173-
onChange: true,
174-
},
175-
});
176-
}
177-
178167
module.exports = ((Switch: any): Class<ReactNative.NativeComponent<Props>>);

Libraries/Components/TabBarIOS/TabBarIOS.ios.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const requireNativeComponent = require('requireNativeComponent');
2222
import type {DangerouslyImpreciseStyleProp} from 'StyleSheet';
2323
import type {ViewProps} from 'ViewPropTypes';
2424

25+
const RCTTabBar = requireNativeComponent('RCTTabBar');
26+
2527
type Props = $ReadOnly<{|
2628
...ViewProps,
2729
style?: DangerouslyImpreciseStyleProp,
@@ -102,6 +104,4 @@ const styles = StyleSheet.create({
102104
},
103105
});
104106

105-
const RCTTabBar = requireNativeComponent('RCTTabBar', TabBarIOS);
106-
107107
module.exports = TabBarIOS;

Libraries/Components/TextInput/TextInput.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,22 @@ let AndroidTextInput;
4040
let RCTMultilineTextInputView;
4141
let RCTSinglelineTextInputView;
4242

43-
const onlyMultiline = {
44-
onTextInput: true,
45-
children: true,
46-
};
47-
4843
if (Platform.OS === 'android') {
49-
AndroidTextInput = requireNativeComponent('AndroidTextInput', null);
44+
AndroidTextInput = requireNativeComponent('AndroidTextInput');
5045
} else if (Platform.OS === 'ios') {
5146
RCTMultilineTextInputView = requireNativeComponent(
5247
'RCTMultilineTextInputView',
53-
null,
5448
);
5549
RCTSinglelineTextInputView = requireNativeComponent(
5650
'RCTSinglelineTextInputView',
57-
null,
5851
);
5952
}
6053

54+
const onlyMultiline = {
55+
onTextInput: true,
56+
children: true,
57+
};
58+
6159
type Event = Object;
6260
type Selection = {
6361
start: number,

Libraries/Components/View/View.js

+1-28
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010

1111
'use strict';
1212

13-
const Platform = require('Platform');
1413
const React = require('React');
15-
const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
1614
const TextAncestor = require('TextAncestor');
17-
const ViewPropTypes = require('ViewPropTypes');
1815

1916
const invariant = require('fbjs/lib/invariant');
2017
const requireNativeComponent = require('requireNativeComponent');
@@ -31,31 +28,7 @@ export type Props = ViewProps;
3128
*
3229
* @see http://facebook.github.io/react-native/docs/view.html
3330
*/
34-
const RCTView = requireNativeComponent(
35-
'RCTView',
36-
{
37-
propTypes: ViewPropTypes,
38-
},
39-
{
40-
nativeOnly: {
41-
nativeBackgroundAndroid: true,
42-
nativeForegroundAndroid: true,
43-
},
44-
},
45-
);
46-
47-
if (__DEV__) {
48-
const UIManager = require('UIManager');
49-
const viewConfig =
50-
(UIManager.viewConfigs && UIManager.viewConfigs.RCTView) || {};
51-
for (const prop in viewConfig.nativeProps) {
52-
if (!ViewPropTypes[prop] && !ReactNativeStyleAttributes[prop]) {
53-
throw new Error(
54-
'View is missing propType for native prop `' + prop + '`',
55-
);
56-
}
57-
}
58-
}
31+
const RCTView = requireNativeComponent('RCTView');
5932

6033
let ViewToExport = RCTView;
6134
if (__DEV__) {

0 commit comments

Comments
 (0)