-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: remove DefaultProps from the StatusBar Component #31631
Conversation
Base commit: e24b55e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to remove defaultProps
from the component but still want the default value to be applied. Right now, whenever you use props.animated
or props.showHideTransition
, the value will be undefined if a user does not supply the prop. We need to make sure all access of these props still have a default value -- we just don't want to use React's defaultProps construct to ensure that.
Please add a snapshot test as well to verify these props. You can take a look at how VirtualizedList does Jest snapshots.
Let me know if that makes sense!
Hi @lunaleaps! Thank you for your suggestion! I just made a new commit could you take a look at it and see if that's what you had in mind? I added default value to the animated prop and showHideTransition prop whenever createStackEntry is called, so when you have animated or showHideTransition set to undefined, the values will be automatically set to false and "fade" respectively. |
@Fannolo Great thank you! Would you also be interested in writing a jest test for this component? You can take a look at VirtualizedList-test as an example: https://github.com/facebook/react-native/blob/dc80b2dcb52fadec6a573a9dd1824393f8c29fdc/Libraries/Lists/__tests__/VirtualizedList-test.js you can check out the Jest API: yarn test [name of your test] |
Hi @lunaleaps, I added some tests to the StaturBar component could you take a look and see if I'm going on the right direction? Thanks! |
@Fannolo Yup! That looks great! Great to assert that the value of the prop is set to its default if not passed in. You can also try running your tests before and after your changes to see if anything has changed. Let me know when you're ready for review again. You can "request changes" from me |
Hi @lunaleaps sorry for the long wait, I checked if the tests were working with the old version of the code and everything looks fine! Lemme know if you can review the pull request! |
@lunaleaps has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
@lunaleaps merged this pull request in 5923ee5. |
Summary
Issue #31607. defaultProps makes it difficult to migrate components to functional.
Changelog
[General] [Changed] - Remove defaultProps from the StatusBar Component.
Test Plan
Verified the behaviour of the existing functionality after the removal on the RN Tester app.
Screen.Recording.2021-05-30.at.00.03.38.mov