From 9be3356e02845a3a8194226a34faa4cb6f7295f1 Mon Sep 17 00:00:00 2001 From: Nadiia D Date: Fri, 13 Nov 2020 17:05:09 -0800 Subject: [PATCH] replace defaultProps usage in functional components Summary: Changelog: [General] [Removed] - Replace defaultProps usage in functional components Reviewed By: kacieb Differential Revision: D24907836 fbshipit-source-id: 05c7381b66c7738790eff5fea594791c3ecfa12e --- .../ActivityIndicator/ActivityIndicator.js | 29 ++++++++++--------- .../ActivityIndicator-test.js.snap | 6 ---- .../ProgressBarAndroid.android.js | 26 ++++++++++------- .../ProgressBarAndroid-test.js.snap | 2 -- Libraries/Components/TextInput/TextInput.js | 24 +++++++++------ .../__snapshots__/TextInput-test.js.snap | 16 ++-------- 6 files changed, 48 insertions(+), 55 deletions(-) diff --git a/Libraries/Components/ActivityIndicator/ActivityIndicator.js b/Libraries/Components/ActivityIndicator/ActivityIndicator.js index 52cbda4a7312e2..05f125d86698bf 100644 --- a/Libraries/Components/ActivityIndicator/ActivityIndicator.js +++ b/Libraries/Components/ActivityIndicator/ActivityIndicator.js @@ -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; @@ -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, @@ -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', diff --git a/Libraries/Components/ActivityIndicator/__tests__/__snapshots__/ActivityIndicator-test.js.snap b/Libraries/Components/ActivityIndicator/__tests__/__snapshots__/ActivityIndicator-test.js.snap index d8316e939d13d1..4326d7f8ae20f3 100644 --- a/Libraries/Components/ActivityIndicator/__tests__/__snapshots__/ActivityIndicator-test.js.snap +++ b/Libraries/Components/ActivityIndicator/__tests__/__snapshots__/ActivityIndicator-test.js.snap @@ -2,9 +2,7 @@ exports[` should render as expected: should deep render when mocked (please verify output manually) 1`] = ` `; @@ -35,18 +33,14 @@ exports[` should render as expected: should deep render whe exports[` should render as expected: should shallow render as when mocked 1`] = ` `; exports[` should render as expected: should shallow render as when not mocked 1`] = ` `; diff --git a/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.android.js b/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.android.js index 61663d6ad50b30..b4d1118cf40533 100644 --- a/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.android.js +++ b/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.android.js @@ -81,23 +81,27 @@ export type ProgressBarAndroidProps = $ReadOnly<{| * ``` */ const ProgressBarAndroid = ( - props: ProgressBarAndroidProps, + { + styleAttr = 'Normal', + indeterminate = true, + animating = true, + ...restProps + }: ProgressBarAndroidProps, forwardedRef: ?React.Ref, ) => { - return ; + return ( + + ); }; 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. */ diff --git a/Libraries/Components/ProgressBarAndroid/__tests__/__snapshots__/ProgressBarAndroid-test.js.snap b/Libraries/Components/ProgressBarAndroid/__tests__/__snapshots__/ProgressBarAndroid-test.js.snap index 87b8c16da4f277..f1985dfedb660a 100644 --- a/Libraries/Components/ProgressBarAndroid/__tests__/__snapshots__/ProgressBarAndroid-test.js.snap +++ b/Libraries/Components/ProgressBarAndroid/__tests__/__snapshots__/ProgressBarAndroid-test.js.snap @@ -18,7 +18,6 @@ exports[` should render as expected: should deep render wh exports[` should render as expected: should shallow render as when mocked 1`] = ` @@ -26,7 +25,6 @@ exports[` should render as expected: should shallow render exports[` should render as expected: should shallow render as when not mocked 1`] = ` diff --git a/Libraries/Components/TextInput/TextInput.js b/Libraries/Components/TextInput/TextInput.js index a46efe02c63e99..03c41c9f9b5b18 100644 --- a/Libraries/Components/TextInput/TextInput.js +++ b/Libraries/Components/TextInput/TextInput.js @@ -1164,21 +1164,27 @@ const ExportedForwardRef: React.AbstractComponent< React.ElementConfig, React.ElementRef> & ImperativeMethods, > = React.forwardRef(function TextInput( - props, + { + allowFontScaling = true, + rejectResponderTermination = true, + underlineColorAndroid = 'transparent', + ...restProps + }, forwardedRef: ReactRefSetter< React.ElementRef> & ImperativeMethods, >, ) { - return ; + return ( + + ); }); -// $FlowFixMe -ExportedForwardRef.defaultProps = { - allowFontScaling: true, - rejectResponderTermination: true, - underlineColorAndroid: 'transparent', -}; - // TODO: Deprecate this // $FlowFixMe ExportedForwardRef.propTypes = DeprecatedTextInputPropTypes; diff --git a/Libraries/Components/TextInput/__tests__/__snapshots__/TextInput-test.js.snap b/Libraries/Components/TextInput/__tests__/__snapshots__/TextInput-test.js.snap index 9ab974ba299412..ea9693e96244c5 100644 --- a/Libraries/Components/TextInput/__tests__/__snapshots__/TextInput-test.js.snap +++ b/Libraries/Components/TextInput/__tests__/__snapshots__/TextInput-test.js.snap @@ -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 when mocked 1`] = ` - -`; +exports[`TextInput tests should render as expected: should shallow render as when mocked 1`] = ``; -exports[`TextInput tests should render as expected: should shallow render as when not mocked 1`] = ` - -`; +exports[`TextInput tests should render as expected: should shallow render as when not mocked 1`] = ``;