Skip to content

Commit

Permalink
Fix more forwardRef displayNames
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sahrens authored and facebook-github-bot committed Jun 19, 2018
1 parent c5ce762 commit 76eebce
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 90 deletions.
20 changes: 10 additions & 10 deletions Libraries/Components/ActivityIndicator/ActivityIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,10 @@ type Props = $ReadOnly<{|
* See http://facebook.github.io/react-native/docs/activityindicator.html
*/
const ActivityIndicator = (
props: $ReadOnly<{|
...Props,
forwardedRef?: ?React.Ref<'RCTActivityIndicatorView'>,
|}>,
props: Props,
forwardedRef?: ?React.Ref<'RCTActivityIndicatorView'>,
) => {
const {onLayout, style, forwardedRef, ...restProps} = props;
const {onLayout, style, ...restProps} = props;
let sizeStyle;

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

return (
<View onLayout={onLayout} style={[styles.container, style]}>
<View
onLayout={onLayout}
style={StyleSheet.compose(
styles.container,
style,
)}>
<RCTActivityIndicator {...nativeProps} />
</View>
);
};

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

ActivityIndicatorWithRef.defaultProps = {
animating: true,
color: Platform.OS === 'ios' ? GRAY : null,
hidesWhenStopped: true,
size: 'small',
};
ActivityIndicatorWithRef.displayName = 'ActivityIndicator';

const styles = StyleSheet.create({
container: {
Expand Down
134 changes: 57 additions & 77 deletions Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,60 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/

'use strict';

const ColorPropType = require('ColorPropType');
const PropTypes = require('prop-types');
const React = require('React');
const ViewPropTypes = require('ViewPropTypes');

const requireNativeComponent = require('requireNativeComponent');

const STYLE_ATTRIBUTES = [
'Horizontal',
'Normal',
'Small',
'Large',
'Inverse',
'SmallInverse',
'LargeInverse',
];
import type {NativeComponent} from 'ReactNative';
import type {ViewProps} from 'ViewPropTypes';

const indeterminateType = function(props, propName, componentName, ...rest) {
const checker = function() {
const indeterminate = props[propName];
const styleAttr = props.styleAttr;
if (!indeterminate && styleAttr !== 'Horizontal') {
return new Error(
'indeterminate=false is only valid for styleAttr=Horizontal',
);
}
};
const AndroidProgressBar = requireNativeComponent('AndroidProgressBar');

return PropTypes.bool(props, propName, componentName, ...rest) || checker();
};
type Props = $ReadOnly<{|
...ViewProps,

/**
* Style of the ProgressBar and whether it shows indeterminate progress (e.g. spinner).
*
* `indeterminate` can only be false if `styleAttr` is Horizontal, and requires a
* `progress` value.
*/
...
| {|
styleAttr: 'Horizontal',
indeterminate: false,
progress: number,
|}
| {|
typeAttr:
| 'Horizontal'
| 'Normal'
| 'Small'
| 'Large'
| 'Inverse'
| 'SmallInverse'
| 'LargeInverse',
indeterminate: true,
|},
/**
* Whether to show the ProgressBar (true, the default) or hide it (false).
*/
animating?: ?boolean,
/**
* Color of the progress bar.
*/
color?: ?string,
/**
* Used to locate this view in end-to-end tests.
*/
testID?: ?string,
|}>;

/**
* React component that wraps the Android-only `ProgressBar`. This component is
Expand All @@ -63,59 +82,20 @@ const indeterminateType = function(props, propName, componentName, ...rest) {
* },
* ```
*/
class ProgressBarAndroid extends React.Component {
static propTypes = {
...ViewPropTypes,

/**
* Style of the ProgressBar. One of:
*
* - Horizontal
* - Normal (default)
* - Small
* - Large
* - Inverse
* - SmallInverse
* - LargeInverse
*/
styleAttr: PropTypes.oneOf(STYLE_ATTRIBUTES),
/**
* Whether to show the ProgressBar (true, the default) or hide it (false).
*/
animating: PropTypes.bool,
/**
* If the progress bar will show indeterminate progress. Note that this
* can only be false if styleAttr is Horizontal.
*/
indeterminate: indeterminateType,
/**
* The progress value (between 0 and 1).
*/
progress: PropTypes.number,
/**
* Color of the progress bar.
*/
color: ColorPropType,
/**
* Used to locate this view in end-to-end tests.
*/
testID: PropTypes.string,
};

static defaultProps = {
styleAttr: 'Normal',
indeterminate: true,
animating: true,
};
const ProgressBarAndroid = (
props: Props,
forwardedRef: ?React.Ref<'AndroidProgressBar'>,
) => {
return <AndroidProgressBar {...props} ref={forwardedRef} />;
};

render() {
const {forwardedRef, ...props} = this.props;
return <AndroidProgressBar {...props} ref={forwardedRef} />;
}
}
// $FlowFixMe - TODO T29156721 `React.forwardRef` is not defined in Flow, yet.
const ProgressBarAndroidToExport = React.forwardRef(ProgressBarAndroid);

const AndroidProgressBar = requireNativeComponent('AndroidProgressBar');
ProgressBarAndroidToExport.defaultProps = {
styleAttr: 'Normal',
indeterminate: true,
animating: true,
};

module.exports = React.forwardRef((props, ref) => (
<ProgressBarAndroid {...props} forwardedRef={ref} />
));
module.exports = (ProgressBarAndroidToExport: Class<NativeComponent<Props>>);
1 change: 0 additions & 1 deletion Libraries/Components/Slider/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ SliderWithRef.defaultProps = {
maximumValue: 1,
step: 0,
};
SliderWithRef.displayName = 'Slider';

let styles;
if (Platform.OS === 'ios') {
Expand Down
1 change: 0 additions & 1 deletion Libraries/Components/View/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ if (__DEV__) {
</TextAncestor.Consumer>
);
};
View.displayName = 'View'; // TODO(T30332650) remove bug workaround
// $FlowFixMe - TODO T29156721 `React.forwardRef` is not defined in Flow, yet.
ViewToExport = React.forwardRef(View);
}
Expand Down
1 change: 0 additions & 1 deletion Libraries/Text/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ const Text = (
) => {
return <TouchableText {...props} forwardedRef={forwardedRef} />;
};
Text.displayName = 'Text'; // TODO(T30332650) remove bug workaround
// $FlowFixMe - TODO T29156721 `React.forwardRef` is not defined in Flow, yet.
const TextToExport = React.forwardRef(Text);

Expand Down

0 comments on commit 76eebce

Please sign in to comment.