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] |
robertKozik
left a comment
There was a problem hiding this comment.
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.
As INACTIVE_POSITION_Y is also a default value for this function, can't we just fling() ?
|
@robertKozik All your comments are now addressed, and the PR description is now updated with screen recordings. |
|
Thanks @burczu will check this PR shortly |
| const INACTIVE_POSITION_Y = -255; | ||
|
|
||
| const PressableWithoutFeedback = Pressables.PressableWithoutFeedback; | ||
| const translateY = new Animated.Value(INACTIVE_POSITION_Y); |
There was a problem hiding this comment.
This value should be preserved in the internal state of the component
There was a problem hiding this comment.
Why? It isn't changed anywhere. In react-native docs they store it in ref... 🤔
There was a problem hiding this comment.
This value changes when you apply Animated.spring(...) and is passed to GrowNotificationContainer as a prop
There was a problem hiding this comment.
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.
ok then - it makes sense! so I'll use useRef here as they do in docs
| */ | ||
| fling(val = INACTIVE_POSITION_Y) { | ||
| Animated.spring(this.state.translateY, { | ||
| const fling = useCallback((val = INACTIVE_POSITION_Y) => { |
There was a problem hiding this comment.
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.
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.
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 |
robertKozik
left a comment
There was a problem hiding this comment.
Test Well, let's push this forward
|
✋ 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
translateYvariable 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 Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.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