Skip to content

Conversation

@kerm1it
Copy link
Contributor

@kerm1it kerm1it commented Jun 2, 2021

Summary

Remove defaultProps from Picker of components, replace it with destructuring assignment.

Changelog

[JavaScript] [Changed] - Remove defaultProps from picker

close #31603

Test Plan

all test suite and CI passes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 2, 2021
@analysis-bot
Copy link

analysis-bot commented Jun 2, 2021

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 819b926

@analysis-bot
Copy link

analysis-bot commented Jun 2, 2021

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 9,240,048 +1,159
android hermes armeabi-v7a 8,749,749 +506
android hermes x86 9,702,653 +1,356
android hermes x86_64 9,667,530 +1,133
android jsc arm64-v8a 10,885,363 -1,239
android jsc armeabi-v7a 9,786,326 -1,913
android jsc x86 10,943,370 -1,042
android jsc x86_64 11,549,773 -1,272

Base commit: 58444c7

@lunaleaps lunaleaps self-requested a review June 2, 2021 17:37

exports[`<Picker /> should render as expected: should shallow render as <Picker /> when mocked 1`] = `
<Picker
mode="dialog"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting, I wouldn't have thought these snapshots would change. Shouldn't we still be setting the prop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because snap only print props of passing to Picker.
After removing defaultProps,it doesn't exist in props.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should still exist in the props we pass because we're setting a default value via the destructured assignment
{mode = MODE_DIALOG...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is a single var rather than a part of props by destructured assignment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is expected. This test is when the component is mocked, so what shows up in the snapshot is exactly what props were passed to Picker, ignoring anything internal to picker.

The change in the test below this kinda surprises me because the title of the test says that isn't mocked. I bet something is wrong in the test there.

Copy link
Contributor Author

@kerm1it kerm1it Jun 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that the results of mock and non-mock are the same in original snapshot, both showing the props passed to Picker.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, missed the fact that it was mocked. @kerm1it did you want to look into why the second snapshot isn't passing mode? If not, I can follow up

Copy link
Contributor Author

@kerm1it kerm1it Jun 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have explained the reason in #31644 (comment) from my opinion.

If you can follow up, I will be happy.

@lunaleaps
Copy link
Contributor

Thanks for working on this @kerm1it! Appreciate your help~

@kerm1it
Copy link
Contributor Author

kerm1it commented Jun 3, 2021

I removed this.props.children,because rest has included children prop.

/* $FlowFixMe[incompatible-type] (>=0.81.0 site=react_native_ios_fb) This
* suppression was added when renaming suppression sites. */
return <PickerIOS {...this.props}>{this.props.children}</PickerIOS>;
return <PickerIOS mode={mode} {...rest} />;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat of a nit and open for discussion but I think it'd be clearer if we kept the children as the "inner child" of this component but I don't feel strongly. We can extract it from this.props on line 170 so you can still spread rest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<PickerIOS mode={mode} {...rest}>
  {children}
</PickerIOS>

this way will appear flow errors:

image


exports[`<Picker /> should render as expected: should shallow render as <Picker /> when mocked 1`] = `
<Picker
mode="dialog"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, missed the fact that it was mocked. @kerm1it did you want to look into why the second snapshot isn't passing mode? If not, I can follow up

@facebook-github-bot
Copy link
Contributor

@lunaleaps has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@lunaleaps merged this pull request in b4cde15.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jun 5, 2021
@kerm1it kerm1it deleted the remove-defaultProps-picker branch June 7, 2021 02:05
@kerm1it
Copy link
Contributor Author

kerm1it commented Jun 7, 2021

b4cde15

There was an obvious problem:

return <PickerIOS {...rest}>{children}</PickerIOS>;

miss mode prop

<PickerAndroid mode={mode}>{children} </PickerAndroid>

miss ...rest

@lunaleaps
Copy link
Contributor

b4cde15

There was an obvious problem:

return <PickerIOS {...rest}>{children}</PickerIOS>;

miss mode prop

<PickerAndroid mode={mode}>{children} </PickerAndroid>

miss ...rest

Ah yup good point. I mistakenly left out the spread of rest. For mode I realized that it's only relevant for Android. Will re-land this

Setito pushed a commit to Setito/react-native that referenced this pull request Jul 17, 2021
Summary:
Remove `defaultProps` from `Picker` of components, replace it with destructuring assignment.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[JavaScript] [Changed] - Remove defaultProps from picker

close facebook#31603

Pull Request resolved: facebook#31644

Test Plan: all test suite and CI passes.

Reviewed By: TheSavior

Differential Revision: D28886320

Pulled By: lunaleaps

fbshipit-source-id: d88a922dffeebe2bce019250d460b5e43a0af562
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove defaultProps from Picker

5 participants