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] Task - Title field is not focused when going back #30366

Closed
6 tasks done
kbecciv opened this issue Oct 25, 2023 · 22 comments
Closed
6 tasks done

[$500] Task - Title field is not focused when going back #30366

kbecciv opened this issue Oct 25, 2023 · 22 comments
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

@kbecciv
Copy link

kbecciv commented Oct 25, 2023

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


Version Number: 1.3.90.2
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: @daveSeife
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1698156938953799

Action Performed:

The title field is not focused when going back

  1. Click on FAB > Assign Task
  2. Write a title and click on next
  3. Click the back button

Expected Result:

The title field is focused when going back

Actual Result:

The title field is not focused when going back

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

Android: Native
XRecorder_24102023_175148.mp4
Android: mWeb Chrome
XRecorder_24102023_175108.mp4
iOS: Native
t8Titlefocus.iosApp.mp4
iOS: mWeb Safari
t8Titlefocus.iosSafari.mp4
MacOS: Chrome / Safari
t8Titlefocus.MacChrome.mp4
MacOS: Desktop
t8Titlefocus.Desktop.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0167a5caffbbaa5a60
  • Upwork Job ID: 1717217726602346496
  • Last Price Increase: 2023-10-25
@kbecciv kbecciv 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 Oct 25, 2023
@melvin-bot melvin-bot bot changed the title Task - Title field is not focused when going back [$500] Task - Title field is not focused when going back Oct 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 25, 2023

Job added to Upwork: https://www.upwork.com/jobs/~0167a5caffbbaa5a60

@melvin-bot
Copy link

melvin-bot bot commented Oct 25, 2023

Triggered auto assignment to @sophiepintoraetz (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 Oct 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 25, 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

@melvin-bot
Copy link

melvin-bot bot commented Oct 25, 2023

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

@paultsimura
Copy link
Contributor

paultsimura commented Oct 25, 2023

Proposal

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

The "Title" field on task creation is not focused on navigating back

What is the root cause of that problem?

For handling the Task's Title field, we use a custom hook: https://github.com/Expensify/App/blob/c3a6b429569474d2e883fb83de802508a85f727a/src/hooks/useAutoFocusInput.js

This hook is intended to handle the Input field's state and auto-focus on navigation, when the screen is focused.

It uses the following useFocusEffect hook to handle the navigation state: whether the screen is focused or not:

useFocusEffect(
useCallback(() => {
focusTimeoutRef.current = setTimeout(() => {
setIsScreenTransitionEnded(true);
}, CONST.ANIMATED_TRANSITION);
return () => {
if (!focusTimeoutRef.current) {
return;
}
clearTimeout(focusTimeoutRef.current);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []),
);

Here, we set the isScreenTransitionEnded to true with some fixed delay when the screen is focused (was navigated to). However, when the screen is unfocused, we only clear the timeout in order to clean up the memory, but we do not reset the isScreenTransitionEnded.

As a result, next time the screen is re-focused, this hook is not triggered, as the isScreenTransitionEnded was not changed (true -> true), and the input is already initialized:

    useEffect(() => {
        if (!isScreenTransitionEnded || !isInputInitialized || !inputRef.current) {
            return;
        }
        inputRef.current.focus();
    }, [isScreenTransitionEnded, isInputInitialized]);

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

Along with clearing the focusTimeoutRef, we should set the isScreenTransitionEnded to false on un-focusing (leaving) the screen:

    useFocusEffect(
        useCallback(() => {
            focusTimeoutRef.current = setTimeout(() => {
                setIsScreenTransitionEnded(true);
            }, CONST.ANIMATED_TRANSITION);
            return () => {
+               setIsScreenTransitionEnded(false);
                if (!focusTimeoutRef.current) {
                    return;
                }
                clearTimeout(focusTimeoutRef.current);
            };
            // eslint-disable-next-line react-hooks/exhaustive-deps
        }, []),
    );

Result:

Screen.Recording.2023-10-25.at.19.35.31.mp4

What alternative solutions did you explore? (Optional)

@rakshitjain13
Copy link
Contributor

@paultsimura Was writing the same proposal but you bumped first! Supafast 💨

@DylanDylann
Copy link
Contributor

Proposal

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

  • Task - Title field is not focused when going back

What is the root cause of that problem?

  • Currently, we are using the below useEffect to focus on the input:
    useEffect(() => {
    if (!isScreenTransitionEnded || !isInputInitialized || !inputRef.current) {
    return;
    }
    inputRef.current.focus();
    }, [isScreenTransitionEnded, isInputInitialized]);
  • When we refocus on this screen, the dependences [isScreenTransitionEnded, isInputInitialized] are not changed (isScreenTransitionEnde is still true) so the callback function in useEffect is not called, that lead to the bug

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

  • We need to setIsScreenTransitionEnded(false) when the screen is blurred by adding setIsScreenTransitionEnded(false)
    to
    return () => {
    if (!focusTimeoutRef.current) {
    return;
    }
    clearTimeout(focusTimeoutRef.current);
    };
  • But when we go to the NewTaskDetailPage screen, there is a delay when focusing on input. So we need to improve this one by using InteractionManager.runAfterInteractions by:
    update
    useFocusEffect(
    useCallback(() => {
    focusTimeoutRef.current = setTimeout(() => {
    setIsScreenTransitionEnded(true);
    }, CONST.ANIMATED_TRANSITION);
    return () => {
    if (!focusTimeoutRef.current) {
    return;
    }
    clearTimeout(focusTimeoutRef.current);
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []),
    );

    to
useFocusEffect(
        useCallback(() => {
            const interactionPromise = InteractionManager.runAfterInteractions(() => {
                setIsScreenTransitionEnded(true);
            });
            return () => {
                setIsScreenTransitionEnded(false);
                interactionPromise.cancel();
            };
        }, []),
    );

What alternative solutions did you explore? (Optional)

  • NA

Result

Screencast.from.26-10-2023.09.46.35.webm

@abdulrahuman5196
Copy link
Contributor

Reviewing now

@abdulrahuman5196
Copy link
Contributor

@paultsimura 's proposal here #30366 (comment) looks good and works well. Other proposals are similar.

🎀 👀 🎀
C+ Reviewed

@melvin-bot
Copy link

melvin-bot bot commented Oct 30, 2023

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

@DylanDylann
Copy link
Contributor

DylanDylann commented Oct 30, 2023

@abdulrahuman5196 my proposal mentioned the solution using InteractionManager.runAfterInteractions, that will fix the issue: delay when refocusing and remove using setTimeout, because i think that using setTimeout is workaround, please help check. cc @nkuoch

@abdulrahuman5196
Copy link
Contributor

@DylanDylann Your proposal is only removing the use of setTimeout with runAfterInteractions, whereas the core issue to fix setIsScreenTransitionEnded(false) remains same. And furthermore runAfterInteractions are not expected to work completely with web, as mentioned in the doc - https://reactnative.dev/docs/interactionmanager

@abdulrahuman5196
Copy link
Contributor

@nkuoch Gentle ping on this #30366 (comment)

@DylanDylann
Copy link
Contributor

@abdulrahuman5196 thanks for review it

@DylanDylann
Copy link
Contributor

@abdulrahuman5196 if we should not use interactionManager, so this problem will be fixed in this one #29009 (comment)

@abdulrahuman5196
Copy link
Contributor

abdulrahuman5196 commented Nov 1, 2023

@sophiepintoraetz Kindly put this issue on hold for #30675? The same is fix being made at a different place.

@melvin-bot melvin-bot bot added the Overdue label Nov 3, 2023
@sophiepintoraetz sophiepintoraetz changed the title [$500] Task - Title field is not focused when going back HOLD [$500] Task - Title field is not focused when going back Nov 6, 2023
@sophiepintoraetz
Copy link
Contributor

Updated!

@melvin-bot melvin-bot bot added Overdue and removed Overdue labels Nov 6, 2023
@paultsimura
Copy link
Contributor

@abdulrahuman5196 the PR we were holding for is now merged. The issue is not reproducible anymore on the latest main.

@sophiepintoraetz
Copy link
Contributor

taking off hold.

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

@abdulrahuman5196 - do you mind confirming if the issue still stands? If not, then I think payments are:
$500 to @DylanDylann and @abdulrahuman5196
$50 to @daveSeife

@sophiepintoraetz sophiepintoraetz changed the title HOLD [$500] Task - Title field is not focused when going back [$500] Task - Title field is not focused when going back Nov 9, 2023
@DylanDylann
Copy link
Contributor

@sophiepintoraetz why 500$ for me? Any mistake here?

@sophiepintoraetz
Copy link
Contributor

@DylanDylann - sorry, I'm getting my issues wired - we're all set here!

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

7 participants