Skip to content

[$1000] mweb - App does not refocus on compose box on message delete using edit mode on android chrome and app #22949

Closed

Description

@kbecciv

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Action Performed:

  1. Open the app
  2. Open any report
  3. Send any message
  4. Edit the message and remove all text
  5. Remove the text and click on green tick
  6. In delete popup, click on delete and observe that app does not refocus on compose box (works fine on web chrome)

Expected Result:

App should refocus on compose box on deleting message using edit mode as it does on web chrome

Actual Result:

App does not refocus on compose box on deleting message using edit mode

Workaround:

Unknown

Platforms:

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

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: 1.3.41-1
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
Notes/Photos/Videos: Any additional supporting documentation

refocus.on.compose.box.on.delete.using.edit.mp4
Screen_Recording_20230715_143240_Chrome.mp4

Expensify/Expensify Issue URL:
Issue reported by: @dhanashree-sawant
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1689363436779099

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~010ac4c166c4d90b1e
  • Upwork Job ID: 1681531735404843008
  • Last Price Increase: 2023-12-02

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jul 15, 2023
  2. melvin-bot commented on Jul 15, 2023

    @melvin-bot

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

  3. melvin-bot commented on Jul 15, 2023

    @melvin-bot

    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
  4. ahmdshrif commented on Jul 15, 2023

    @ahmdshrif
    Contributor

    Proposal

    Please restate the problem that we are trying to solve in this issue.

    when deleting the edit message main composer does not focus again.
    also when canceling the edit composer does not focus again.

    What is the root cause of that problem?

    main composer set is not render whe we edit message and we run show composer and focus without wait the composer render again.

    ComposerActions.setShouldShowComposeInput(true);
    ReportActionComposeFocusManager.focus();

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

    we can simply wait until the composer is showing and then focus it using runAfterInteractions.

    ComposerActions.setShouldShowComposeInput(true);
    InteractionManager.runAfterInteractions(() => {
        ReportActionComposeFocusManager.focus();
    });

    What alternative solutions did you explore? (Optional)

    N/A

    Screen_Recording_20230716_004412_Chrome.mp4
  5. bernhardoj commented on Jul 16, 2023

    @bernhardoj
    Contributor

    Proposal

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

    On mobile web, closing the edit composer does not refocus back the main composer.

    What is the root cause of that problem?

    On a small-screen device, when we focus on an edit composer, the main composer will hide.

    setShouldShowComposeInputKeyboardAware(false);

    Either saving or closing the edit composer, it will call deleteDraft which will try to focus back to the main composer (ReportActionComposeFocusManager.focus()).

    const deleteDraft = useCallback(() => {
    InputFocus.callback(() => setIsFocused(false));
    InputFocus.inputFocusChange(false);
    debouncedSaveDraft.cancel();
    Report.saveReportActionDraft(props.reportID, props.action, '');
    if (isActive()) {
    ReportActionComposeFocusManager.clear();
    ReportActionComposeFocusManager.focus();
    }

    However, at this point, the main composer is still hidden. We will show the main composer back when the active edit composer is unmounted (or blurred).

    return () => {
    // Skip if the current report action is not active
    if (!isActive()) {
    return;
    }
    if (EmojiPickerAction.isActive(props.action.reportActionID)) {
    EmojiPickerAction.clearActive();
    }
    if (ReportActionContextMenu.isActiveReportAction(props.action.reportActionID)) {
    ReportActionContextMenu.clearActiveReportAction();
    }
    // Show the main composer when the focused message is deleted from another client
    // to prevent the main composer stays hidden until we swtich to another chat.
    setShouldShowComposeInputKeyboardAware(true);
    };

    So, the focus always fails.

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

    When we save/cancel the edit composer, the component will be unmounted. So, we should focus back on the main composer when the component is unmounted and also wait for the Onyx process to complete by making setShouldShowComposeInputKeyboardAware as a Promise.

    setShouldShowComposeInputKeyboardAware(true).then(() => {
        ReportActionComposeFocusManager.clear();
        ReportActionComposeFocusManager.focus();
    });
    

    To make setShouldShowComposeInputKeyboardAware as a Promise,

    1. Return the Onyx set in here
      function setShouldShowComposeInput(shouldShowComposeInput: boolean) {
      Onyx.set(ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT, shouldShowComposeInput);
      }
    2. In setShouldShowComposeInputKeyboardAware/index, return the promise from Composer.setShouldShowComposeInput
      const setShouldShowComposeInputKeyboardAware: SetShouldShowComposeInputKeyboardAware = (shouldShow) => {
      Composer.setShouldShowComposeInput(shouldShow);
      };
    3. In setShouldShowComposeInputKeyboardAwareBuilder, return a new Promise object which will be resolved by Composer.setShouldShowComposeInput promise.
      const setShouldShowComposeInputKeyboardAwareBuilder: (keyboardEvent: KeyboardEventName) => SetShouldShowComposeInputKeyboardAware =
      (keyboardEvent: KeyboardEventName) => (shouldShow: boolean) => {
      if (keyboardEventListener) {
      keyboardEventListener.remove();
      keyboardEventListener = null;
      }
      if (!shouldShow) {
      Composer.setShouldShowComposeInput(false);
      return;
      }
      // If keyboard is already hidden, we should show composer immediately because keyboardDidHide event won't be called
      if (!Keyboard.isVisible()) {
      Composer.setShouldShowComposeInput(true);
      return;
      }
      keyboardEventListener = Keyboard.addListener(keyboardEvent, () => {
      Composer.setShouldShowComposeInput(true);
      keyboardEventListener?.remove();
      });
      };
    => new Promise(resolve => {
        ...
    
        if (!shouldShow) {
            Composer.setShouldShowComposeInput(false).then(resolve);
        ...
    
        if (!Keyboard.isVisible()) {
            Composer.setShouldShowComposeInput(true).then(resolve);
        ...
    
        keyboardEventListener = Keyboard.addListener(keyboardEvent, () => {
            Composer.setShouldShowComposeInput(true).then(resolve);
    })
    
  6. allroundexperts commented on Jul 16, 2023

    @allroundexperts
    Contributor

    Proposal

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

    Closing the edit composer does not re-focus the main composer on mweb.

    What is the root cause of that problem?

    As correctly pointed out by previous proposals, the root cause is that on small screens the main composer is hidden when the edit composer is visible. We're triggering focus when hiding the edit composer. However, It takes some time for the edit composer to hide and for the main composer to show up. This causes the main composer to be not focused.

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

    I think this problem is very common and we should queue our focus requests to the main composer. We already have a ReportActionComposeFocusManager and we can use it to queue the focus action. In order to do this, we can create a new variable called pendingFocus and set its value to false initially. Then we can change our current focus function inside ReportActionComposeFocusManager to be:

    function focus() {
        if (!_.isFunction(focusCallback)) {
            pendingFocus = true;
            return;
        }
    
        focusCallback();
        pendingFocus = false;
    }
    

    Similarly, the clear function would be changed to:

    function clear() {
        focusCallback = null;
        pendingFocus = false;
    }
    

    Lastly, the onComposerFocus function would be changed to:

    function onComposerFocus(callback) {
        focusCallback = callback;
        if (pendingFocus) {
            callback();
            pendingFocus = false;
        }
    }
    

    Result

    Screen.Recording.2023-07-16.at.7.17.05.PM.mov

    What alternative solutions did you explore? (Optional)

    None

  7. tjferriss commented on Jul 17, 2023

    @tjferriss
    Contributor

    I'm not able to reproduce the issue on the desktop app. The app correctly refocuses on the compose box.

    Screen.Recording.2023-07-17.at.10.37.12.mov
  8. dhanashree-sawant commented on Jul 17, 2023

    @dhanashree-sawant

    Hi @tjferriss, the issue is specifically on android chrome and android app, sorry for confusion, it is not on desktop app

  9. allroundexperts commented on Jul 18, 2023

    @allroundexperts
    Contributor

    @tjferriss This is still easily reproducible on android chrome. Can you please open this?

  10. tjferriss commented on Jul 18, 2023

    @tjferriss
    Contributor

    Thanks @allroundexperts. I've re-opened so we can investigate.

  11. 89 remaining items

  12. aimane-chnaif commented on Nov 30, 2023

    @aimane-chnaif
    Contributor

    Refocus still happens after deleting message on android chrome. This is bug to fix I think as native, mSafari doesn't refocus at all.

  13. bernhardoj commented on Nov 30, 2023

    @bernhardoj
    Contributor

    It didn't refocus on me.

    Screen.Recording.2023-11-30.at.17.00.14.mov

    If we look at the code, we want to refocus the composer when deleting a draft.

    /**
    * Delete the draft of the comment being edited. This will take the comment out of "edit mode" with the old content.
    */
    const deleteDraft = useCallback(() => {
    InputFocus.callback(() => setIsFocused(false));
    InputFocus.inputFocusChange(false);
    debouncedSaveDraft.cancel();
    Report.saveReportActionDraft(props.reportID, props.action, '');
    if (isActive()) {
    ReportActionComposeFocusManager.clear();
    ReportActionComposeFocusManager.focus();
    }

    The refocus will only work for web platform (willBlurTextInputOnTapOutside).

    const setUpComposeFocusManager = useCallback(() => {
    // This callback is used in the contextMenuActions to manage giving focus back to the compose input.
    ReportActionComposeFocusManager.onComposerFocus(() => {
    if (!willBlurTextInputOnTapOutside || !isFocused) {
    return;
    }
    focus(false);
    }, true);
    }, [focus, isFocused]);

    But it's currently not working on mWeb (at least on my end)

    Maybe we should clarify the expected behavior here.
    Do we want to refocus back to the main composer after closing the edit composer (web only)?

    If not, then we can remove the logic from the edit composer.

  14. aimane-chnaif commented on Nov 30, 2023

    @aimane-chnaif
    Contributor

    It didn't refocus on me.

    I tested on physical device. From your video, I found another bug of glitch which means try to refocus again and failed

  15. aimane-chnaif commented on Nov 30, 2023

    @aimane-chnaif
    Contributor

    reproducible on android emulator as well

    android.emulator.mov
  16. bernhardoj commented on Nov 30, 2023

    @bernhardoj
    Contributor

    From your video, I found another bug of glitch which means try to refocus again and failed

    Looks like on my end (emulator and real device), it refocuses back to the edit composer. Anyway, we need to decide first whether to refocus back to main composer or not.

  17. melvin-bot commented on Dec 2, 2023

    @melvin-bot

    📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

  18. aimane-chnaif commented on Dec 2, 2023

    @aimane-chnaif
    Contributor

    I don't think it's expected behavior to refocus upon cancelling edit mode on mobile. Keyboard re-popup really annoys users including me.
    Refocus happens after deleting message on edit mode on android chrome. This is inconsistency bug to fix I think, as native and mSafari don't refocus at all.

    🎀 👀 🎀 to confirm with engineer

  19. melvin-bot commented on Dec 2, 2023

    @melvin-bot

    Triggered auto assignment to @yuwenmemon, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

  20. tjferriss commented on Dec 5, 2023

    @tjferriss
    Contributor

    I tend to agree with @aimane-chnaif synopsis above. I think we can safely close this issue and revisit it down the road.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2EngineeringExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributors

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions