-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix: Composer is not focused when press Message User in Profile page #30973
Conversation
@hoangzinh 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] |
src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js
Show resolved
Hide resolved
@@ -499,6 +499,22 @@ function ComposerWithSuggestions({ | |||
} | |||
focus(); | |||
}, [focus, prevIsFocused, editFocused, prevIsModalVisible, isFocused, modal.isVisible, isNextModalWillOpenRef]); | |||
|
|||
const shouldAutoFocusRef = useRef(false); | |||
shouldAutoFocusRef.current = shouldAutoFocus; |
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.
Is there any reason why we don't use shouldAutoFocus
directly, but using ref here?
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 won't need this anymore in the latest approach. Thanks.
Note: autoFocus prop is only used to focus the input on the mount and this is its main The solution does not match the proposal. Can we please explain this in the PR description? |
useEffect(() => { | ||
if (prevIsFocused || !isFocused) { | ||
return; | ||
} | ||
// Focus composer when navigating from another screen | ||
setTimeout(() => { | ||
if (!shouldAutoFocusRef.current) { | ||
return; | ||
} | ||
textInputRef.current.focus(); | ||
}, CONST.ANIMATED_TRANSITION); | ||
}, [isFocused, prevIsFocused]); |
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 setTimeouts. We should fix the existing focus handler effect.
@@ -498,7 +498,9 @@ function ComposerWithSuggestions({ | |||
return; | |||
} | |||
focus(); | |||
// eslint-disable-next-line react-hooks/exhaustive-deps |
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.
@tienifr could you share why we don't add shouldAutoFocus to the dependency array?
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.
I don't think we should run the effect again when shouldAutoFocus
changes. It's just a check. The effect should only be re-triggered when some modal close/open or the page gets focused.
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.
do you mind sharing will it cause any regression bugs if we add this value to the dependency list?
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.
cc @tienifr ^
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.
Not yet found any regression so far. My initial idea was to limit the number of re-render by avoiding unncessary dependency. But as I tested and confirmed that it did not affect re-render performance.
@@ -491,6 +491,7 @@ function ComposerWithSuggestions({ | |||
const prevIsModalVisible = usePrevious(modal.isVisible); | |||
const prevIsFocused = usePrevious(isFocused); | |||
useEffect(() => { | |||
console.log('abcdef'); |
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.
Is it accidentally added?
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.
My bad! Removed!
Reviewer Checklist
Screenshots/VideosAndroid: NativeAndroid: mWeb ChromeScreen.Recording.2023-11-30.at.18.27.00.-.android.chrome.moviOS: NativeScreen.Recording.2023-11-30.at.19.33.35.-.ios.mp4iOS: mWeb SafariScreen.Recording.2023-11-30.at.19.33.35.-.ios.mp4MacOS: Chrome / SafariScreen.Recording.2023-11-30.at.17.14.53.-.web.movMacOS: DesktopScreen.Recording.2023-11-30.at.17.15.42.-.desktop.mov |
✋ 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/Gonals in version: 1.4.7-0 🚀
|
🚀 Deployed to production by https://github.com/yuwenmemon in version: 1.4.7-4 🚀
|
Details
Composer is not focused when press Message User in Profile page. This PR fixes that.
Fixed Issues
$ #30254
PROPOSAL: #30254 (comment)
Tests
Offline tests
NA
QA Steps
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
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
Android: Native
Screen.Recording.2023-11-08.at.16.29.37-compressed.mov
Android: mWeb Chrome
Screen.Recording.2023-11-08.at.16.30.52-compressed.mov
iOS: Native
Screen.Recording.2023-11-08.at.16.25.32-compressed.mov
iOS: mWeb Safari
Screen.Recording.2023-11-08.at.16.26.42-compressed.mov
MacOS: Chrome / Safari
Screen.Recording.2023-11-07.at.17.37.29-compressed.mov
MacOS: Desktop
Screen.Recording.2023-11-08.at.15.29.22-compressed.mov