-
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
Fix - mWeb auto focus on reply in thread #37929
Fix - mWeb auto focus on reply in thread #37929
Conversation
@allroundexperts 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] |
Reviewer Checklist
Screenshots/VideosAndroid: NativeScreen.Recording.2024-04-02.at.4.44.22.PM.movAndroid: mWeb ChromeScreen.Recording.2024-04-02.at.4.42.02.PM.moviOS: NativeScreen.Recording.2024-04-02.at.4.41.13.PM.moviOS: mWeb SafariScreen.Recording.2024-04-02.at.4.39.43.PM.movMacOS: Chrome / SafariScreen.Recording.2024-04-02.at.4.23.07.PM.movMacOS: DesktopScreen.Recording.2024-04-02.at.4.25.33.PM.mov |
src/components/Composer/index.tsx
Outdated
if (isReportActionCompose) { | ||
ReportActionComposeFocusManager.onComposerFocus(null); | ||
} else { | ||
// While a user was editing a comment and if they open on LHN menu we want the focus to return | ||
// to the ReportActionItemMessageEdit compose after they click on the menu (for e.g. mark as read) | ||
// so we assign the focus callback here. | ||
ReportActionComposeFocusManager.onComposerFocus(() => { | ||
if (!textInput.current) { | ||
return; | ||
} | ||
|
||
textInput.current.focus(); | ||
}); | ||
} |
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.
if (isReportActionCompose) { | |
ReportActionComposeFocusManager.onComposerFocus(null); | |
} else { | |
// While a user was editing a comment and if they open on LHN menu we want the focus to return | |
// to the ReportActionItemMessageEdit compose after they click on the menu (for e.g. mark as read) | |
// so we assign the focus callback here. | |
ReportActionComposeFocusManager.onComposerFocus(() => { | |
if (!textInput.current) { | |
return; | |
} | |
textInput.current.focus(); | |
}); | |
} | |
ReportActionComposeFocusManager.onComposerFocus(() => { | |
/* | |
While a user was editing a comment and if they open on LHN menu we want the focus to return | |
to the ReportActionItemMessageEdit compose after they click on the menu (for e.g. mark as read) | |
so we assign the focus callback here. | |
*/ | |
if (!textInput.current || isReportActionCompose) { | |
return; | |
} | |
textInput.current.focus(); | |
}); |
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.
Nope. What we are trying to avoid for main composer is overriding of the focus callback; onComposerFocus
is callback assigner so we should avoid overriding of mainComposerFocusCallback
by focusCallback
so when isReportActionCompose
is true we reset it to null
.
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 still don't get the reasoning behind this. Why can't we just return early in the callback if isReportActionCompose
is true
?
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.
What we want to achieve is when the focus is called from reply in thread we want to focus the compose in the newly created thread and we can do that via mainComposerFocusCallback
set here
App/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx
Lines 611 to 617 in 822cf62
ReportActionComposeFocusManager.onComposerFocus((shouldFocusForNative = false) => { | |
if ((!willBlurTextInputOnTapOutside && !shouldFocusForNative) || !isFocused) { | |
return; | |
} | |
focus(false); | |
}, true); |
But mainComposerFocusCallback are only called when
focusCallback
is not set.App/src/libs/ReportActionComposeFocusManager.ts
Lines 38 to 43 in 822cf62
if (typeof focusCallback !== 'function') { | |
if (typeof mainComposerFocusCallback !== 'function') { | |
return; | |
} | |
mainComposerFocusCallback(shouldFocusForNative); |
So here what we want is to reset
focusCallback
to null so that our mainComposerFocusCallback will be called. But early returning, as U suggest, means we leave (without reseting) what was already set on focusCallback
therefore our mainComposerFocusCallback
will not be called.
@FitseTLT Please ensure that the screen recordings are available on ALL the platforms. |
ping |
Bump @allroundexperts |
Replied again @FitseTLT |
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.
Looks good to me!
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.
A have a small suggestion on the comment to improve the readability. Code LGTM - just need to improve quality.
@@ -29,7 +29,7 @@ function onComposerFocus(callback: FocusCallback, isMainComposer = false) { | |||
/** | |||
* Request focus on the ReportActionComposer | |||
*/ | |||
function focus() { | |||
function focus(shouldFocusForNative?: boolean) { |
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.
Having a shouldFocusForNative
param seems to encourages code that is not cross platform.
Can we rename this to indicate the intended behavior regardless of what platform we are on?
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.
Can we rename this to indicate the intended behavior regardless of what platform we are on?
That isn't clear @marcaaron. Because we are early returning here
App/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx
Lines 612 to 613 in a4d01a8
if (!willBlurTextInputOnTapOutside || !isFocused) { | |
return; |
willBlurTextInputOnTapOutside
is false only for natives so we are normally preventing focus for natives but in our case we have to manually focus it for natives too that's why I came up with the variable. What other name could we give?
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.
Naming it shouldReturnEarly
should be fine @FitseTLT. We do not support code that this written just for native platforms mixed together with the rest of the code. If we need to do something specific to the native platform, we usually create a separate file .native.ts
extension to keep proper separation of concerns.
@@ -200,7 +201,9 @@ const ContextMenuActions: ContextMenuAction[] = [ | |||
onPress: (closePopover, {reportAction, reportID}) => { | |||
if (closePopover) { | |||
hideContextMenu(false, () => { | |||
ReportActionComposeFocusManager.focus(); | |||
InteractionManager.runAfterInteractions(() => { | |||
ReportActionComposeFocusManager.focus(true); |
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.
Please add a comment here to explain why we are passing true
.
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.
added but can u check the comments.
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.
Let's avoid creating platform specific language.
Can you answer this question without referencing "native":
What behavior are we giving the callback by passing true
?
@marcaaron @allroundexperts Changed the variable name to |
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.
Much better thanks!
✋ 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/marcaaron in version: 1.4.61-0 🚀
|
🚀 Deployed to staging by https://github.com/marcaaron in version: 1.4.61-0 🚀
|
🚀 Deployed to production by https://github.com/Julesssss in version: 1.4.61-8 🚀
|
Details
Fixed Issues
$ #30689
PROPOSAL: #30689 (comment)
Tests
On mWeb:
Offline tests
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)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label so the design team can review the changes.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
nat.mp4
Android: mWeb Chrome
android.web.mp4
iOS: Native
2024-03-26.16-35-25.mp4
iOS: mWeb Safari
ios.web.mp4
MacOS: Chrome / Safari
2024-03-26.16-09-52.mp4
MacOS: Desktop
2024-03-26.16-37-03.mp4