Skip to content

Commit

Permalink
replace defaultProps usage in functional components
Browse files Browse the repository at this point in the history
Summary:
Changelog:
[General] [Removed] - Replace defaultProps usage in functional components

Reviewed By: kacieb

Differential Revision: D24907836

fbshipit-source-id: 05c7381b66c7738790eff5fea594791c3ecfa12e
  • Loading branch information
Nadiia D authored and facebook-github-bot committed Nov 14, 2020
1 parent 2798e71 commit 9be3356
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 55 deletions.
29 changes: 16 additions & 13 deletions Libraries/Components/ActivityIndicator/ActivityIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,18 @@ type Props = $ReadOnly<{|
size?: ?IndicatorSize,
|}>;

const ActivityIndicator = (props: Props, forwardedRef?: any) => {
const {onLayout, style, size, ...restProps} = props;
const ActivityIndicator = (
{
animating = true,
color = Platform.OS === 'ios' ? GRAY : null,
hidesWhenStopped = true,
onLayout,
size = 'small',
style,
...restProps
}: Props,
forwardedRef?: any,
) => {
let sizeStyle;
let sizeProp;

Expand All @@ -77,11 +87,14 @@ const ActivityIndicator = (props: Props, forwardedRef?: any) => {
sizeProp = 'large';
break;
default:
sizeStyle = {height: props.size, width: props.size};
sizeStyle = {height: size, width: size};
break;
}

const nativeProps = {
animating,
color,
hidesWhenStopped,
...restProps,
ref: forwardedRef,
style: sizeStyle,
Expand Down Expand Up @@ -178,16 +191,6 @@ const ActivityIndicatorWithRef: React.AbstractComponent<
> = React.forwardRef(ActivityIndicator);
ActivityIndicatorWithRef.displayName = 'ActivityIndicator';

/* $FlowFixMe(>=0.89.0 site=react_native_fb) This comment suppresses an error
* found when Flow v0.89 was deployed. To see the error, delete this comment
* and run Flow. */
ActivityIndicatorWithRef.defaultProps = {
animating: true,
color: Platform.OS === 'ios' ? GRAY : null,
hidesWhenStopped: true,
size: 'small',
};

const styles = StyleSheet.create({
container: {
alignItems: 'center',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

exports[`<ActivityIndicator /> should render as expected: should deep render when mocked (please verify output manually) 1`] = `
<ActivityIndicator
animating={true}
color="#0000ff"
hidesWhenStopped={true}
size="large"
/>
`;
Expand Down Expand Up @@ -35,18 +33,14 @@ exports[`<ActivityIndicator /> should render as expected: should deep render whe

exports[`<ActivityIndicator /> should render as expected: should shallow render as <ActivityIndicator /> when mocked 1`] = `
<ActivityIndicator
animating={true}
color="#0000ff"
hidesWhenStopped={true}
size="large"
/>
`;

exports[`<ActivityIndicator /> should render as expected: should shallow render as <ActivityIndicator /> when not mocked 1`] = `
<ActivityIndicator
animating={true}
color="#0000ff"
hidesWhenStopped={true}
size="large"
/>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,27 @@ export type ProgressBarAndroidProps = $ReadOnly<{|
* ```
*/
const ProgressBarAndroid = (
props: ProgressBarAndroidProps,
{
styleAttr = 'Normal',
indeterminate = true,
animating = true,
...restProps
}: ProgressBarAndroidProps,
forwardedRef: ?React.Ref<typeof ProgressBarAndroidNativeComponent>,
) => {
return <ProgressBarAndroidNativeComponent {...props} ref={forwardedRef} />;
return (
<ProgressBarAndroidNativeComponent
styleAttr={styleAttr}
indeterminate={indeterminate}
animating={animating}
{...restProps}
ref={forwardedRef}
/>
);
};

const ProgressBarAndroidToExport = React.forwardRef(ProgressBarAndroid);

/* $FlowFixMe(>=0.89.0 site=react_native_android_fb) This comment suppresses an
* error found when Flow v0.89 was deployed. To see the error, delete this
* comment and run Flow. */
ProgressBarAndroidToExport.defaultProps = {
styleAttr: 'Normal',
indeterminate: true,
animating: true,
};

/* $FlowFixMe(>=0.89.0 site=react_native_android_fb) This comment suppresses an
* error found when Flow v0.89 was deployed. To see the error, delete this
* comment and run Flow. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ exports[`<ProgressBarAndroid /> should render as expected: should deep render wh

exports[`<ProgressBarAndroid /> should render as expected: should shallow render as <ProgressBarAndroid /> when mocked 1`] = `
<ForwardRef(ProgressBarAndroid)
animating={true}
indeterminate={true}
styleAttr="Horizontal"
/>
`;

exports[`<ProgressBarAndroid /> should render as expected: should shallow render as <ProgressBarAndroid /> when not mocked 1`] = `
<ForwardRef(ProgressBarAndroid)
animating={true}
indeterminate={true}
styleAttr="Horizontal"
/>
Expand Down
24 changes: 15 additions & 9 deletions Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -1164,21 +1164,27 @@ const ExportedForwardRef: React.AbstractComponent<
React.ElementConfig<typeof InternalTextInput>,
React.ElementRef<HostComponent<mixed>> & ImperativeMethods,
> = React.forwardRef(function TextInput(
props,
{
allowFontScaling = true,
rejectResponderTermination = true,
underlineColorAndroid = 'transparent',
...restProps
},
forwardedRef: ReactRefSetter<
React.ElementRef<HostComponent<mixed>> & ImperativeMethods,
>,
) {
return <InternalTextInput {...props} forwardedRef={forwardedRef} />;
return (
<InternalTextInput
allowFontScaling={allowFontScaling}
rejectResponderTermination={rejectResponderTermination}
underlineColorAndroid={underlineColorAndroid}
{...restProps}
forwardedRef={forwardedRef}
/>
);
});

// $FlowFixMe
ExportedForwardRef.defaultProps = {
allowFontScaling: true,
rejectResponderTermination: true,
underlineColorAndroid: 'transparent',
};

// TODO: Deprecate this
// $FlowFixMe
ExportedForwardRef.propTypes = DeprecatedTextInputPropTypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,6 @@ exports[`TextInput tests should render as expected: should deep render when not
/>
`;

exports[`TextInput tests should render as expected: should shallow render as <TextInput /> when mocked 1`] = `
<ForwardRef(TextInput)
allowFontScaling={true}
rejectResponderTermination={true}
underlineColorAndroid="transparent"
/>
`;
exports[`TextInput tests should render as expected: should shallow render as <TextInput /> when mocked 1`] = `<ForwardRef(TextInput) />`;

exports[`TextInput tests should render as expected: should shallow render as <TextInput /> when not mocked 1`] = `
<ForwardRef(TextInput)
allowFontScaling={true}
rejectResponderTermination={true}
underlineColorAndroid="transparent"
/>
`;
exports[`TextInput tests should render as expected: should shallow render as <TextInput /> when not mocked 1`] = `<ForwardRef(TextInput) />`;

0 comments on commit 9be3356

Please sign in to comment.