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

[HOLD for payment 2024-11-22] [$250] Pressing up arrow to edit the previous message, there is a bad overlap with the recipients local time. #51431

Open
1 of 8 tasks
m-natarajan opened this issue Oct 24, 2024 · 18 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@m-natarajan
Copy link

m-natarajan commented Oct 24, 2024

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: 9.0.53-1
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?:
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: @tgolen
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1729781934730029

Action Performed:

  1. Go to staging.new.expensify.com
  2. DM any user and send multiple messages
  3. Click the up arrow on keyboard to edit the last message sent

Expected Result:

User able to edit last message sent and no visual issues

Actual Result:

Selected message box overlaps with the recipients local time

Workaround:

Unknown

Platforms:

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

  • Android: Standalone
  • Android: HybridApp
  • Android: mWeb Chrome
  • iOS: Standalone
  • iOS: HybridApp
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

image (3)

Google Chrome 2024-10-24 at 10 49 46

Snip - (55) New Expensify - Google Chrome (2)

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021851399834739628625
  • Upwork Job ID: 1851399834739628625
  • Last Price Increase: 2024-11-05
Issue OwnerCurrent Issue Owner: @strepanier03
@m-natarajan m-natarajan added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Oct 24, 2024
Copy link

melvin-bot bot commented Oct 24, 2024

Triggered auto assignment to @strepanier03 (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@shahinyan11
Copy link

shahinyan11 commented Oct 24, 2024

Edited by proposal-police: This proposal was edited at 2024-10-24 19:35:48 UTC.

Proposal

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

Pressing up arrow to edit the previous message, there is a bad overlap with the recipients local time.

What is the root cause of that problem?

The message edit mode container is large and the scroll position remains the same after expanding the content.

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

Add following line const reportScrollManager = useReportScrollManager() in ComposerWithSuggestions component and add bellow code after this line

InteractionManager.runAfterInteractions(()=>{
    reportScrollManager.scrollToBottom()
})

What alternative solutions did you explore? (Optional)

Add bellow useEffect in ReportActionItem component

useEffect(() => {
    if(!draftMessage) return
    
    InteractionManager.runAfterInteractions(()=>{
        reportScrollManager.scrollToIndex(index)
    })
}, [draftMessage, index]);

What alternative solutions did you explore? (Optional)

Add bellow useEffect in ReportActionItemMessageEdit component

useEffect(() => {    
    InteractionManager.runAfterInteractions(()=>{
        reportScrollManager.scrollToIndex(index)
    })
}, [index]);

We can also use setTimeout(()=>{}, 0) instead of InteractionManager.runAfterInteractions everywhere

@bernhardoj
Copy link
Contributor

Proposal

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

Pressing the up arrow to edit the last message doesn't show it fully.

What is the root cause of that problem?

In our custom MVCPFlatList, we enable the maintainVisibleContentPosition to maintain the position of the message when the content size changes by scrolling it by the offset of the size differences. But, we also have the mvcpAutoscrollToTopThresholdRef which should auto-scroll to the bottom if it's within the threshold (250).

if (Math.abs(delta) > (IS_MOBILE_SAFARI ? 100 : 0.5)) {
const scrollOffset = lastScrollOffsetRef.current;
prevFirstVisibleOffsetRef.current = firstVisibleViewOffset;
scrollToOffset(scrollOffset + delta, false, true);
if (mvcpAutoscrollToTopThresholdRef.current != null && scrollOffset <= mvcpAutoscrollToTopThresholdRef.current) {
scrollToOffset(0, true, false);
}
}

The issue in this case is, the scroll to the bottom (0) doesn't work and looks like it's conflicting with the edit composer focus. For the scroll to bottom, we set the scroll animated to true (2nd param), which will set the behavior to smooth scrolling. So, the edit composer focus interrupt the scrolling.

scrollToOffset(scrollOffset + delta, false, true);
if (mvcpAutoscrollToTopThresholdRef.current != null && scrollOffset <= mvcpAutoscrollToTopThresholdRef.current) {
scrollToOffset(0, true, false);

If we remove auto-focus from the edit composer, then it works fine, but we can't do that.

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

If the mutation is an addition of an edit composer, then don't scroll with animation.

First, adjustForMaintainVisibleContentPosition will accept a new props to decide whether to animate the scroll or not and pass it to the scroll function.

const adjustForMaintainVisibleContentPosition = useCallback(() => {

scrollToOffset(0, true, false);

const adjustForMaintainVisibleContentPosition = useCallback((animated = true) => {
    ...
    scrollToOffset(0, animated, false);

Then, we check if the mutation list contains an added nodes of the edit composer.

const mutationObserver = new MutationObserver((mutations) => {
// Check if the first visible view is removed and re-calculate it
// if needed.
mutations.forEach((mutation) => {
mutation.removedNodes.forEach((node) => {
if (node !== firstVisibleViewRef.current) {
return;
}
firstVisibleViewRef.current = null;
});
});
if (firstVisibleViewRef.current == null) {
prepareForMaintainVisibleContentPosition();
}
// When the list is hidden, the size will be 0.
// Ignore the callback if the list is hidden because scrollOffset will always be 0.
if (!getScrollableNode(scrollRef.current)?.clientHeight) {
return;
}
adjustForMaintainVisibleContentPosition();
prepareForMaintainVisibleContentPosition();
});

let isEditComposerAdded = false;
mutations.forEach((mutation) => {
    ...

    mutation.addedNodes.forEach((node) => {
        if (node.nodeType === Node.ELEMENT_NODE && node.dataset.isEditing === "true") {
            isEditComposerAdded = true;
            return;
        }
    });
});

...

adjustForMaintainVisibleContentPosition(!isEditComposerAdded);
prepareForMaintainVisibleContentPosition();

If an edit composer action is added, then we pass the animated as false. We check whether it's an edit composer action by checking the node.dataset.isEditing === "true" instead of recursively checking the children to make it simpler (let me know if we want to recursively checking the children).

Last, we need to add the isEditing dataset to the element here.

<View style={highlightedBackgroundColorIfNeeded}>

<View style={highlightedBackgroundColorIfNeeded} dataSet={{isEditing: !!draftMessage}}>

What alternative solutions did you explore? (Optional)

We have a few alternatives here.

Delay the auto scroll to bottom here using InteractionManager, let the focus happens first.

if (mvcpAutoscrollToTopThresholdRef.current != null && scrollOffset <= mvcpAutoscrollToTopThresholdRef.current) {
scrollToOffset(0, true, false);
}

Delay the focus using InteractionManager,

Promise.all([ComposerFocusManager.isReadyToFocus(), isWindowReadyToFocus()]).then(() => {
if (!textInput) {
return;
}
textInput.focus();
if (forcedSelectionRange) {
setTextInputSelection(textInput, forcedSelectionRange);
}
});

OR we can wait for the scroll event to ends, but the scroll end event actually just use setTimeout 250ms after there is no onScroll event received anymore.

if (lastScrollEvent.current) {
scrollEndTimeout.current = setTimeout(() => {
if (lastScrollEvent.current !== timestamp) {
return;
}
// Scroll has ended
lastScrollEvent.current = null;
onScrollEnd();
}, 250);

We can manually scroll when the edit composer is focused, but reportScrollManager.scrollToIndex is currently only made for native because in web, we don't want to scroll the edit composer to bottom when editing it.

onFocus={() => {
setIsFocused(true);
if (textInputRef.current) {
ReportActionComposeFocusManager.editComposerRef.current = textInputRef.current;
}
InteractionManager.runAfterInteractions(() => {
requestAnimationFrame(() => {
reportScrollManager.scrollToIndex(index, true);
});
});

const scrollToIndex = useCallback(
(index: number, isEditing?: boolean) => {
if (!flatListRef?.current || isEditing) {
return;
}
flatListRef.current.scrollToIndex({index, animated: true});
},

So, what we can do is to only scroll if it's the last action.

reportScrollManager.scrollToIndex(index, isLastVisibleReportAction);

We can get the last visible report action inside getFirstVisibleReportActionID. We will rename it to getFirstAndLastVisibleReportActionID

const firstVisibleReportActionID = useMemo(() => ReportActionsUtils.getFirstVisibleReportActionID(sortedReportActions, isOffline), [sortedReportActions, isOffline]);

function getFirstAndLastVisibleReportActionID(sortedReportActions: ReportAction[] = [], isOffline = false): [string, string] {
    if (!Array.isArray(sortedReportActions)) {
        return ['', ''];
    }
    const sortedFilterReportActions = sortedReportActions.filter((action) => !isDeletedAction(action) || (action?.childVisibleActionCount ?? 0) > 0 || isOffline);
    return sortedFilterReportActions.length > 1 ? [
        sortedFilterReportActions.at(sortedFilterReportActions.length - 2)?.reportActionID ?? '-1',
        sortedFilterReportActions.at(0)?.reportActionID ?? '-1',
    ] : ['', ''];
}

Then, pass isLastVisibleReportAction just like isFirstVisibleReportAction

isFirstVisibleReportAction={firstVisibleReportActionID === reportAction.reportActionID}
shouldUseThreadDividerLine={shouldUseThreadDividerLine}

If we want to always scroll the edit composer to bottom (specifically to put it above the main composer), then we can remove the isEditing here.

const scrollToIndex = useCallback(
(index: number, isEditing?: boolean) => {
if (!flatListRef?.current || isEditing) {
return;
}
flatListRef.current.scrollToIndex({index, animated: true});

@adelekennedy
Copy link

I think this issue may be a dupe (thank you @shahinyan11!) closing in favor if this one as it already has a proposal

@melvin-bot melvin-bot bot added the Overdue label Oct 28, 2024
@raza-ak
Copy link
Contributor

raza-ak commented Oct 28, 2024

Proposal

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

Pressing up arrow to edit the previous message, there is a bad overlap with the recipients local time.

What is the root cause of that problem?

Enabling edit mode triggers a slight upward movement of the scrollbar, which shifts the layout and results in an overlap between the message editing area and the recipient's local time display.

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

A useEffect hook was implemented to automatically scroll to the bottom after the component finishes rendering in edit mode. This ensures that the edit section is fully visible and prevents any overlap with the recipient’s local time.
Following changes will fix the issue:
image

Video:

380152981-e3cb759d-fbbe-4ec1-862f-39a7a989edbb.mp4

Copy link

melvin-bot bot commented Oct 29, 2024

@strepanier03 Eep! 4 days overdue now. Issues have feelings too...

@strepanier03 strepanier03 added the External Added to denote the issue can be worked on by a contributor label Oct 29, 2024
@melvin-bot melvin-bot bot changed the title Pressing up arrow to edit the previous message, there is a bad overlap with the recipients local time. [$250] Pressing up arrow to edit the previous message, there is a bad overlap with the recipients local time. Oct 29, 2024
Copy link

melvin-bot bot commented Oct 29, 2024

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

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Oct 29, 2024
Copy link

melvin-bot bot commented Oct 29, 2024

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

@melvin-bot melvin-bot bot removed the Overdue label Oct 29, 2024
@strepanier03
Copy link
Contributor

Repro'd pretty easily. This is mostly just a polish project as it doesn't impact the customer's ability to use the product nor drive forward other projects.

image

Copy link

melvin-bot bot commented Nov 4, 2024

@strepanier03, @Ollyws Huh... This is 4 days overdue. Who can take care of this?

@melvin-bot melvin-bot bot added the Overdue label Nov 4, 2024
@Ollyws
Copy link
Contributor

Ollyws commented Nov 4, 2024

Will get to this one tomorrow morning.

@melvin-bot melvin-bot bot removed the Overdue label Nov 4, 2024
Copy link

melvin-bot bot commented Nov 5, 2024

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

@Ollyws
Copy link
Contributor

Ollyws commented Nov 5, 2024

@bernhardoj's proposal LGTM.
🎀👀🎀 C+ reviewed

Copy link

melvin-bot bot commented Nov 5, 2024

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

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Nov 5, 2024
@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Nov 6, 2024
@bernhardoj
Copy link
Contributor

PR is ready

cc: @Ollyws

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Nov 15, 2024
@melvin-bot melvin-bot bot changed the title [$250] Pressing up arrow to edit the previous message, there is a bad overlap with the recipients local time. [HOLD for payment 2024-11-22] [$250] Pressing up arrow to edit the previous message, there is a bad overlap with the recipients local time. Nov 15, 2024
Copy link

melvin-bot bot commented Nov 15, 2024

Reviewing label has been removed, please complete the "BugZero Checklist".

@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Nov 15, 2024
Copy link

melvin-bot bot commented Nov 15, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.62-4 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2024-11-22. 🎊

For reference, here are some details about the assignees on this issue:

  • @Ollyws requires payment through NewDot Manual Requests
  • @bernhardoj requires payment through NewDot Manual Requests

Copy link

melvin-bot bot commented Nov 15, 2024

@Ollyws @strepanier03 @Ollyws The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2
Projects
Status: No status
Development

No branches or pull requests

8 participants