-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
migration from class to functional component #23911
migration from class to functional component #23911
Conversation
@robertKozik Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
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.
Could you please take one more look at the show function, as for now, it's not working properly? Also, please update the screenshots/videos accordingly, as this component is used in the app.
|
||
fling(0); | ||
setTimeout(() => { | ||
fling(INACTIVE_POSITION_Y); |
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.
As INACTIVE_POSITION_Y
is also a default value for this function, can't we just fling()
?
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.
Yes, make sense!
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.
resolved
@robertKozik All your comments are now addressed, and the PR description is now updated with screen recordings. |
Thanks @burczu will check this PR shortly |
@@ -29,24 +29,12 @@ const types = { | |||
const INACTIVE_POSITION_Y = -255; | |||
|
|||
const PressableWithoutFeedback = Pressables.PressableWithoutFeedback; | |||
const translateY = new Animated.Value(INACTIVE_POSITION_Y); |
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.
This value should be preserved in the internal state of the component
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.
Why? It isn't changed anywhere. In react-native docs they store it in ref... 🤔
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.
This value changes when you apply Animated.spring(...) and is passed to GrowNotificationContainer as a prop
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.
The translateY is defined outside the functional component, which means that it will be shared across all instances of this component and will only be defined once, during the initialization of the module. If this value needs to be preserved for each individual instance of the component, it should be managed within the component's internal state or with a useRef hook. This approach ensures that the lifecycle of the translateY value is properly tied to each instance of the component, which allow more predictable behavior and avoiding potential bugs.
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.
@ArekChr that's an excellent explanation 😄
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.
ok then - it makes sense! so I'll use useRef
here as they do in docs
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.
resolved
|
||
/** | ||
* Animate growl notification | ||
* | ||
* @param {Number} val | ||
*/ | ||
fling(val = INACTIVE_POSITION_Y) { | ||
Animated.spring(this.state.translateY, { | ||
const fling = useCallback((val = INACTIVE_POSITION_Y) => { |
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.
No child component is wrapped with memo, so useCallback won't do any optimization between renders
Nvm, this is necessary! Thanks @gedu 😄
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.
It is being used in the useEffect
so it must be a stable function, so it needs the useCallback
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.
Good point! I think this should be mentioned on React core docs
Reviewer Checklist
Screenshots/VideosWebweb.movMobile Web - Chromeandroid.-.web.movMobile Web - SafariiOS.-.web.movDesktopdesktop.moviOSiOS.-.native.movAndroidandroid.-.native.mov |
@burczu if you could add the test steps for this PR. I forgot to mention it when asking for videos. Sorry for inconvenience |
@robertKozik Added test steps |
One thing during testing: BUG: Clicking on growl notification makes it stay visible forever - WEB (CHROME) Screen.Recording.2023-08-01.at.14.31.38.mov |
@robertKozik I'll check it but I don't think it's related with this issue, and not even sure if its a bug or rather a feature ;) |
@robertKozik ok - checked on new.expensify.com and clicking on the toast should close it immediately - I'll try to fix it then |
@robertKozik fixed |
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.
Test Well, let's push this forward
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.
Thanks guys!
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by https://github.com/mountiny in version: 1.3.50-0 🚀
|
🚀 Deployed to production by https://github.com/puneetlath in version: 1.3.50-3 🚀
|
🚀 Deployed to staging by https://github.com/mountiny in version: 1.3.51-0 🚀
|
🚀 Deployed to production by https://github.com/Julesssss in version: 1.3.51-2 🚀
|
Details
Simple migration of the class component into the functional component with some minor improvement like moving
translateY
variable outside the component because it does not change anywhere.Fixed Issues
$ #16154
PROPOSAL:
Tests
Offline tests
Same as above
QA Steps
Same as above
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Web
23911-web.mp4
Mobile Web - Chrome
23911-android-web.mp4
Mobile Web - Safari
23911-ios-web.mp4
Desktop
23911-desktop.mp4
iOS
23911-ios.mp4
Android
23911-android.mp4