Skip to content
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

[$500] Thread - The cursor is not focused when opening a previously created thread. #30986

Closed
5 of 6 tasks
izarutskaya opened this issue Nov 7, 2023 · 10 comments
Closed
5 of 6 tasks
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors

Comments

@izarutskaya
Copy link

izarutskaya commented Nov 7, 2023

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: v1.3.96-0
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: Applause-Internal Team
Slack conversation: @

Action Performed:

  1. Go to https://staging.new.expensify.com/
  2. Log in with any account.
  3. Navigate to 1:1 conversation.
  4. Start a thread in owned message.
  5. Go back and open the thread link.

Expected Result:

Cursor is focused.

Actual Result:

The cursor is not focused when opening a previously created thread.

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6267033_1699348180023.Missing_cursor_when_opening_a_previously_created_thread.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01f0a8339a7396a1b3
  • Upwork Job ID: 1721862265009238016
  • Last Price Increase: 2023-11-07
@izarutskaya izarutskaya added External Added to denote the issue can be worked on by a contributor Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Nov 7, 2023
@melvin-bot melvin-bot bot changed the title Thread - The cursor is not focused when opening a previously created thread. [$500] Thread - The cursor is not focused when opening a previously created thread. Nov 7, 2023
Copy link

melvin-bot bot commented Nov 7, 2023

Job added to Upwork: https://www.upwork.com/jobs/~01f0a8339a7396a1b3

Copy link

melvin-bot bot commented Nov 7, 2023

Triggered auto assignment to @lschurr (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Nov 7, 2023
Copy link

melvin-bot bot commented Nov 7, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

Copy link

melvin-bot bot commented Nov 7, 2023

Triggered auto assignment to Contributor-plus team member for initial proposal review - @allroundexperts (External)

@FitseTLT
Copy link
Contributor

FitseTLT commented Nov 7, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

The cursor not auto focused when opening previously created thread

What is the root cause of that problem?

Auto focus is disabled in mobile for non empty chat for the main composer. It is because shouldAutoFocus which sets autoFocus prop of Composer is false if it is non empty chat for mobile (shouldFocusInputOnScreenFocus is false for mobile) as isEmptyChat will be false here

const shouldAutoFocus = !modal.isVisible && (shouldFocusInputOnScreenFocus || (isEmptyChat && !ReportActionsUtils.isTransactionThread(parentAction))) && shouldShowComposeInput;

What changes do you think we should make in order to solve the problem?

We should focus before navigate to child report here

onPress={() => {
Report.navigateToAndOpenChildReport(props.childReportID);
}}

calling ReportActionComposeFocusManager.focus

onPress={() => {
                    ReportActionComposeFocusManager.focus();
                    Report.navigateToAndOpenChildReport(props.childReportID);                    
                }}

Then we should update this code

function focusComposerWithDelay(textInput: TextInput | null): FocusComposerWithDelay {
/**
* Focus the text input
* @param [shouldDelay] Impose delay before focusing the text input
*/
return (shouldDelay = false) => {
// There could be other animations running while we trigger manual focus.
// This prevents focus from making those animations janky.
InteractionManager.runAfterInteractions(() => {
if (!textInput || EmojiPickerAction.isEmojiPickerVisible()) {
return;
}
if (!shouldDelay) {
textInput.focus();
return;
}
ComposerFocusManager.isReadyToFocus().then(() => {
if (!textInput) {
return;
}
textInput.focus();
});
});
};
}

to

function focusComposerWithDelay(textInputRef: TextInput | null): FocusComposerWithDelay {
    /**
     * Focus the text input
     * @param [shouldDelay] Impose delay before focusing the text input
     */
    return (shouldDelay = false) => {
        // There could be other animations running while we trigger manual focus.
        // This prevents focus from making those animations janky.
        InteractionManager.runAfterInteractions(() => {
            const textInput = textInputRef || ReportActionComposeFocusManager.composerRef.current;

            if (!textInput || EmojiPickerAction.isEmojiPickerVisible()) {
                return;
            }

            if (!shouldDelay) {
                textInput.focus();
                return;
            }
            ComposerFocusManager.isReadyToFocus().then(() => {
                if (!textInput) {
                    return;
                }
                textInput.focus();
            });
        });
    };
}

To set the ref to ReportActionComposeFocusManager.composerRef which points to the currently rendered main composer. The reason we do that is as we are navigating to other screen if we pass the text input ref in here when the focus function is called in focusComposerWithDelay after the page is navigated to thread the ref will be an obsolete already unmounted one and our focus will not work 👍
Lastly we will change

onFocus={(e) => {
ReportActionComposeFocusManager.onComposerFocus(() => {
if (!textInput.current) {
return;
}

to

 onFocus={(e) => {
                    if (isMainComposer) ReportActionComposeFocusManager.onComposerFocus(null);
                    else
                        ReportActionComposeFocusManager.onComposerFocus(() => {
                            if (!textInput.current) {
                                return;
                            }

                            textInput.current.focus();
                        });

This onComposerFocus is called to set the focus callback to fix this issue which is related to focus problem on web in whichReportActionItemMessageEdit composer losing focus to main composer after pressing LHN menu item. So we will pass isMainComposer prop (as true) to Composer for the main composer (ComposerWithSuggestions) and whenever the composer is focused if it is main composer we will reset the focus callback to null because we will use mainComposerFocusCallback for the main composer and only set the focus fallback for the ReportActionItemMessageEdit compsoer to preserve the fix for that issue. But the reason we add this condition is because with the existing code whenever the main compose is focused this function is always called changing the focus callback to other callback than the mainComposerFocusCallback (which focuses the correct compose text input ref). Hence, relpy in thread will still not auto focus if we have focused on the composer anytime after our latest reload of the page as the focus callback set here will execute which tries to focuses the wrong textInput ref which is the unmounted text input 👍 .

What alternative solutions did you explore? (Optional)

@dummy-1111
Copy link
Contributor

This looks like an intentional behavior. We don't auto focus on mobile devices
if we still want to focus, we need to have discussions and set clear expectation, I think

cc @allroundexperts @lschurr

@DylanDylann
Copy link
Contributor

DylanDylann commented Nov 8, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

  • Thread - The cursor is not focused when opening a previously created thread

What is the root cause of that problem?

  • Currently, we use the variable shouldAutoFocus to know should we auto-focus on the composer or not:
    const shouldAutoFocus = !modal.isVisible && (shouldFocusInputOnScreenFocus || (isEmptyChat && !ReportActionsUtils.isTransactionThread(parentAction))) && shouldShowComposeInput;
  • With the mobile device, we will auto-focus in case isEmptyChat and !ReportActionsUtils.isTransactionThread(parentAction), so in case of this bug, the thread report is not focused automatically.

What changes do you think we should make in order to solve the problem?

  • We can update the shouldAutoFocus to:
const shouldAutoFocus = !modal.isVisible && (shouldFocusInputOnScreenFocus || ((isEmptyChat|| ReportUtils.isThread(report)) && !ReportActionsUtils.isTransactionThread(parentAction))) && shouldShowComposeInput;

What alternative solutions did you explore? (Optional)

  • NA

@melvin-bot melvin-bot bot added the Overdue label Nov 9, 2023
@lschurr
Copy link
Contributor

lschurr commented Nov 9, 2023

@allroundexperts could you review?

@melvin-bot melvin-bot bot removed the Overdue label Nov 9, 2023
@allroundexperts
Copy link
Contributor

@lschurr I would agree with @s-alves10 here. As far as I remember, we don't autofocus on mobile intentionally. Can you please confirm if this is really a bug? Thanks!

@lschurr
Copy link
Contributor

lschurr commented Nov 13, 2023

Let's go ahead and close. Thanks!

@lschurr lschurr closed this as completed Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors
Projects
None yet
Development

No branches or pull requests

6 participants