Skip to content

Commit 76eebce

Browse files
sahrensfacebook-github-bot
authored andcommitted
Fix more forwardRef displayNames
Summary: See https://reactjs.org/docs/forwarding-refs.html#displaying-a-custom-name-in-devtools reapply of D8342904 Reviewed By: yungsters Differential Revision: D8465006 fbshipit-source-id: f196f39b9b1c9bbe16a845667ebbdb21953a5848
1 parent c5ce762 commit 76eebce

File tree

5 files changed

+67
-90
lines changed

5 files changed

+67
-90
lines changed

Libraries/Components/ActivityIndicator/ActivityIndicator.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,10 @@ type Props = $ReadOnly<{|
7070
* See http://facebook.github.io/react-native/docs/activityindicator.html
7171
*/
7272
const ActivityIndicator = (
73-
props: $ReadOnly<{|
74-
...Props,
75-
forwardedRef?: ?React.Ref<'RCTActivityIndicatorView'>,
76-
|}>,
73+
props: Props,
74+
forwardedRef?: ?React.Ref<'RCTActivityIndicatorView'>,
7775
) => {
78-
const {onLayout, style, forwardedRef, ...restProps} = props;
76+
const {onLayout, style, ...restProps} = props;
7977
let sizeStyle;
8078

8179
switch (props.size) {
@@ -99,24 +97,26 @@ const ActivityIndicator = (
9997
};
10098

10199
return (
102-
<View onLayout={onLayout} style={[styles.container, style]}>
100+
<View
101+
onLayout={onLayout}
102+
style={StyleSheet.compose(
103+
styles.container,
104+
style,
105+
)}>
103106
<RCTActivityIndicator {...nativeProps} />
104107
</View>
105108
);
106109
};
107110

108111
// $FlowFixMe - TODO T29156721 `React.forwardRef` is not defined in Flow, yet.
109-
const ActivityIndicatorWithRef = React.forwardRef((props: Props, ref) => {
110-
return <ActivityIndicator {...props} forwardedRef={ref} />;
111-
});
112+
const ActivityIndicatorWithRef = React.forwardRef(ActivityIndicator);
112113

113114
ActivityIndicatorWithRef.defaultProps = {
114115
animating: true,
115116
color: Platform.OS === 'ios' ? GRAY : null,
116117
hidesWhenStopped: true,
117118
size: 'small',
118119
};
119-
ActivityIndicatorWithRef.displayName = 'ActivityIndicator';
120120

121121
const styles = StyleSheet.create({
122122
container: {

Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.android.js

Lines changed: 57 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,60 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7+
* @flow
78
* @format
89
*/
910

1011
'use strict';
1112

12-
const ColorPropType = require('ColorPropType');
13-
const PropTypes = require('prop-types');
1413
const React = require('React');
15-
const ViewPropTypes = require('ViewPropTypes');
1614

1715
const requireNativeComponent = require('requireNativeComponent');
1816

19-
const STYLE_ATTRIBUTES = [
20-
'Horizontal',
21-
'Normal',
22-
'Small',
23-
'Large',
24-
'Inverse',
25-
'SmallInverse',
26-
'LargeInverse',
27-
];
17+
import type {NativeComponent} from 'ReactNative';
18+
import type {ViewProps} from 'ViewPropTypes';
2819

29-
const indeterminateType = function(props, propName, componentName, ...rest) {
30-
const checker = function() {
31-
const indeterminate = props[propName];
32-
const styleAttr = props.styleAttr;
33-
if (!indeterminate && styleAttr !== 'Horizontal') {
34-
return new Error(
35-
'indeterminate=false is only valid for styleAttr=Horizontal',
36-
);
37-
}
38-
};
20+
const AndroidProgressBar = requireNativeComponent('AndroidProgressBar');
3921

40-
return PropTypes.bool(props, propName, componentName, ...rest) || checker();
41-
};
22+
type Props = $ReadOnly<{|
23+
...ViewProps,
24+
25+
/**
26+
* Style of the ProgressBar and whether it shows indeterminate progress (e.g. spinner).
27+
*
28+
* `indeterminate` can only be false if `styleAttr` is Horizontal, and requires a
29+
* `progress` value.
30+
*/
31+
...
32+
| {|
33+
styleAttr: 'Horizontal',
34+
indeterminate: false,
35+
progress: number,
36+
|}
37+
| {|
38+
typeAttr:
39+
| 'Horizontal'
40+
| 'Normal'
41+
| 'Small'
42+
| 'Large'
43+
| 'Inverse'
44+
| 'SmallInverse'
45+
| 'LargeInverse',
46+
indeterminate: true,
47+
|},
48+
/**
49+
* Whether to show the ProgressBar (true, the default) or hide it (false).
50+
*/
51+
animating?: ?boolean,
52+
/**
53+
* Color of the progress bar.
54+
*/
55+
color?: ?string,
56+
/**
57+
* Used to locate this view in end-to-end tests.
58+
*/
59+
testID?: ?string,
60+
|}>;
4261

4362
/**
4463
* React component that wraps the Android-only `ProgressBar`. This component is
@@ -63,59 +82,20 @@ const indeterminateType = function(props, propName, componentName, ...rest) {
6382
* },
6483
* ```
6584
*/
66-
class ProgressBarAndroid extends React.Component {
67-
static propTypes = {
68-
...ViewPropTypes,
69-
70-
/**
71-
* Style of the ProgressBar. One of:
72-
*
73-
* - Horizontal
74-
* - Normal (default)
75-
* - Small
76-
* - Large
77-
* - Inverse
78-
* - SmallInverse
79-
* - LargeInverse
80-
*/
81-
styleAttr: PropTypes.oneOf(STYLE_ATTRIBUTES),
82-
/**
83-
* Whether to show the ProgressBar (true, the default) or hide it (false).
84-
*/
85-
animating: PropTypes.bool,
86-
/**
87-
* If the progress bar will show indeterminate progress. Note that this
88-
* can only be false if styleAttr is Horizontal.
89-
*/
90-
indeterminate: indeterminateType,
91-
/**
92-
* The progress value (between 0 and 1).
93-
*/
94-
progress: PropTypes.number,
95-
/**
96-
* Color of the progress bar.
97-
*/
98-
color: ColorPropType,
99-
/**
100-
* Used to locate this view in end-to-end tests.
101-
*/
102-
testID: PropTypes.string,
103-
};
104-
105-
static defaultProps = {
106-
styleAttr: 'Normal',
107-
indeterminate: true,
108-
animating: true,
109-
};
85+
const ProgressBarAndroid = (
86+
props: Props,
87+
forwardedRef: ?React.Ref<'AndroidProgressBar'>,
88+
) => {
89+
return <AndroidProgressBar {...props} ref={forwardedRef} />;
90+
};
11091

111-
render() {
112-
const {forwardedRef, ...props} = this.props;
113-
return <AndroidProgressBar {...props} ref={forwardedRef} />;
114-
}
115-
}
92+
// $FlowFixMe - TODO T29156721 `React.forwardRef` is not defined in Flow, yet.
93+
const ProgressBarAndroidToExport = React.forwardRef(ProgressBarAndroid);
11694

117-
const AndroidProgressBar = requireNativeComponent('AndroidProgressBar');
95+
ProgressBarAndroidToExport.defaultProps = {
96+
styleAttr: 'Normal',
97+
indeterminate: true,
98+
animating: true,
99+
};
118100

119-
module.exports = React.forwardRef((props, ref) => (
120-
<ProgressBarAndroid {...props} forwardedRef={ref} />
121-
));
101+
module.exports = (ProgressBarAndroidToExport: Class<NativeComponent<Props>>);

Libraries/Components/Slider/Slider.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ SliderWithRef.defaultProps = {
250250
maximumValue: 1,
251251
step: 0,
252252
};
253-
SliderWithRef.displayName = 'Slider';
254253

255254
let styles;
256255
if (Platform.OS === 'ios') {

Libraries/Components/View/View.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ if (__DEV__) {
4545
</TextAncestor.Consumer>
4646
);
4747
};
48-
View.displayName = 'View'; // TODO(T30332650) remove bug workaround
4948
// $FlowFixMe - TODO T29156721 `React.forwardRef` is not defined in Flow, yet.
5049
ViewToExport = React.forwardRef(View);
5150
}

Libraries/Text/Text.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ const Text = (
267267
) => {
268268
return <TouchableText {...props} forwardedRef={forwardedRef} />;
269269
};
270-
Text.displayName = 'Text'; // TODO(T30332650) remove bug workaround
271270
// $FlowFixMe - TODO T29156721 `React.forwardRef` is not defined in Flow, yet.
272271
const TextToExport = React.forwardRef(Text);
273272

0 commit comments

Comments
 (0)