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-01-26] [$500] Emoji - When resizing the window, the open emoji picker moves to the LHN side #31155

Closed
2 of 6 tasks
lanitochka17 opened this issue Nov 9, 2023 · 93 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering Internal Requires API changes or must be handled by Expensify staff

Comments

@lanitochka17
Copy link

lanitochka17 commented Nov 9, 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: 1.3.97-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. Open https://staging.new.expensify.com/
  2. Log in with any account
  3. Open any report
  4. In Compose Box, open the emoji picker
  5. Reduce the width of the open browser window

Expected Result:

Emoji picker should be fixed above the Compose Box when resizing the window and should remain open when going into mobile mode

Actual Result:

When resizing the window, the open emoji picker moves to the LHN side

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

Bug6270312_1699554384569.Recording__692.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01b9e60337c2ef461a
  • Upwork Job ID: 1722692276888514560
  • Last Price Increase: 2023-11-30
@lanitochka17 lanitochka17 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 9, 2023
@melvin-bot melvin-bot bot changed the title Emoji - When resizing the window, the open emoji picker moves to the LHN side [$500] Emoji - When resizing the window, the open emoji picker moves to the LHN side Nov 9, 2023
Copy link

melvin-bot bot commented Nov 9, 2023

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

Copy link

melvin-bot bot commented Nov 9, 2023

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

Copy link

melvin-bot bot commented Nov 9, 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 melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Nov 9, 2023
Copy link

melvin-bot bot commented Nov 9, 2023

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

@jeet-dhandha
Copy link
Contributor

jeet-dhandha commented Nov 9, 2023

Proposal

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

  • Emoji picker sticking to left side of screen when we resize the window horizontally.

What is the root cause of that problem?

  • In below code snippet the value comes as {horizontal: 0, vertical: 0} when we resize the window horizontally.

calculateAnchorPosition(emojiPopoverAnchor.current, emojiPopoverAnchorOrigin).then((value) => {

  • This happens because when we copy reference of anchor element and then measure it's position using measureInWindow the response of callback comes as (x, y, width, height) => (0, 0, 0, 0) when we resize the window horizontally.

  • And if we check the original anchor element's position using measure it's position is correct.

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

  • First we create a useDimensionChange hook which will take a callback function and will call it whenever the dimension of the element changes.
  • then we move the calculate logic to a function onAnchorDimensionChange which takes the original ref and pass it to useImperativeHandle.

const emojiPopoverDimensionListener = Dimensions.addEventListener('change', () => {
if (!emojiPopoverAnchor.current) {
// In small screen width, the window size change might be due to keyboard open/hide, we should avoid hide EmojiPicker in those cases
if (isEmojiPickerVisible && !isSmallScreenWidth) {
hideEmojiPicker();
}
return;
}
calculateAnchorPosition(emojiPopoverAnchor.current, emojiPopoverAnchorOrigin).then((value) => {
setEmojiPopoverAnchorPosition(value);
});
});

  • then we create a onAnchorDimensionChange function in EmojiPickerAction.ts and call it in useDimensionChange at each place where we use the showEmojiPicker function.

Below example is for EmojiPickerButton.js but we have to do the same for other places where we use showEmojiPicker function.

// `emojiPopoverAnchor.current` is the original ref of the anchor element from `EmojiPickerButton.js`
useDimensionChange(() => EmojiPickerAction.onAnchorDimensionChange(emojiPopoverAnchor.current));

Video for EmojiPickerButton.js

video
c8046c9e-f613-4550-b13f-b300ef68a079.mp4

What alternative solutions did you explore? (Optional)

  • N/A

@tienifr
Copy link
Contributor

tienifr commented Nov 10, 2023

Proposal

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

When resizing the window, the open emoji picker moves to the LHN side

What is the root cause of that problem?

When we resize the window, the ref of the emoji button here will change, however, since we only passed the value (.current) of that ref here as the anchorRef, that anchorRef does not change and points to a non-existent component, leading to the dimensions become all 0 and the emoji picker moves to LHN side.

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

The way we're passing refs as params to other components are not ideal, that way the original ref and the ref that we pass can get out of sync, causing issues like this one.

So the pattern that we use is usually:

  • Create and update the ref inside the anchor component (in this case, inside EmojiPickerButton)
  • Pass that ref to another component that displays the actual popover (in this case, the EmojiPicker)
  1. We need to make sure they are always in sync, or ideally, always 1 single ref. We should create a new hook useSyncedRef that will return 1 ref for both components.
import React from 'react';

const refs = {}

const useSyncedRef = (refKey, initialValue = undefined) => {
  if (!refs[refKey]) {
    refs[refKey] = React.createRef(initialValue);
  }

  const refCallback = (value) => {
    refs[refKey].current = value;
  }

  return { ref: refs[refKey], refCallback };
}

export default useSyncedRef;
  1. In EmojiPickerButton here
const {refCallback} = useSyncedRef('EmojiPickerAnchor');

And replace this
with

ref={refCallback}
  1. In EmojiPicker here, replace with
const { ref: emojiPopoverAnchor } = useSyncedRef('EmojiPickerAnchor');

And we don't need to pass the ref from the EmojiPickerButton to EmojiPicker via showEmojiPicker any more.

What alternative solutions did you explore? (Optional)

We can just add another method updateAnchorRef inside EmojiPicker and call it whenever the ref is updated in EmojiPickerButton

Any place that has this issue can be fixed the same way by the main or alternative approach, but the main approach is global.

@bernhardoj
Copy link
Contributor

bernhardoj commented Nov 10, 2023

Proposal

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

Resizing the browser window moves the emoji picker to the left side of the screen.

What is the root cause of that problem?

In EmojiPicker, we have a dimension change listener to calculate a new position.

const emojiPopoverDimensionListener = Dimensions.addEventListener('change', () => {
if (!emojiPopoverAnchor.current) {
// In small screen width, the window size change might be due to keyboard open/hide, we should avoid hide EmojiPicker in those cases
if (isEmojiPickerVisible && !isSmallScreenWidth) {
hideEmojiPicker();
}
return;
}
calculateAnchorPosition(emojiPopoverAnchor.current, emojiPopoverAnchorOrigin).then((value) => {
setEmojiPopoverAnchorPosition(value);
});
});

The problem is, that the x, y, w, and h returned from calculateAnchorPosition is 0.

This is because the element we want to measure (emojiPopoverAnchor.current) is not available on the dom anymore. emojiPopoverAnchor in this case is the emoji picker button.

The element becomes not available as soon as the emoji picker menu shows. Why?

The emoji picker button is wrapped with a PopoverAnchorTooltip.

<Tooltip text={props.translate('reportActionCompose.emoji')}>
<PressableWithoutFeedback
ref={emojiPopoverAnchor}

PopoverAnchorTooltip will conditionally render the element with/without a tooltip based on the popover visibility.

if (!shouldRender || isPopoverRelatedToTooltipOpen) {
return children;
}
return (
<BaseTooltip
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
tooltipRef={tooltipRef}
>
{children}
</BaseTooltip>
);

When we first open the web, the emoji picker button is rendered with a tooltip, but when the emoji picker popover shows, we render the emoji picker button without a tooltip. This becomes a problem because if we render it with a tooltip, we clone the children (in this case the emoji picker button). So, both elements are different instances and the element that we pass to the EmojiPicker is the element of the with a tooltip.

EmojiPickerAction.showEmojiPicker(props.onModalHide, props.onEmojiSelected, emojiPopoverAnchor.current, undefined, () => {}, props.emojiPickerID);

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

Instead of passing the element as the emojiPopoverAnchorValue to EmojiPicker, we should pass the ref object so we can always get the latest value from the ref object.

-EmojiPickerAction.showEmojiPicker(props.onModalHide, props.onEmojiSelected, emojiPopoverAnchor.current, undefined, () => {}, props.emojiPickerID);
+EmojiPickerAction.showEmojiPicker(props.onModalHide, props.onEmojiSelected, emojiPopoverAnchor, undefined, () => {}, props.emojiPickerID);

We should make the above changes to every usage of EmojiPickerAction.showEmojiPicker

Then, we need to modify EmojiPicker so it works with the ref, that is by accessing the element by using double .current.

if (emojiPopoverAnchor.current && emojiPopoverAnchor.current.blur) {
// Drop focus to avoid blue focus ring.
emojiPopoverAnchor.current.blur();
}
const anchorOriginValue = anchorOrigin || DEFAULT_ANCHOR_ORIGIN;
calculateAnchorPosition(emojiPopoverAnchor.current, anchorOriginValue).then((value) => {

if (!emojiPopoverAnchor.current) {
// In small screen width, the window size change might be due to keyboard open/hide, we should avoid hide EmojiPicker in those cases
if (isEmojiPickerVisible && !isSmallScreenWidth) {
hideEmojiPicker();
}
return;
}
calculateAnchorPosition(emojiPopoverAnchor.current, emojiPopoverAnchorOrigin).then((value) => {

emojiPopoverAnchor.current.current

the first .current is to access the emojiPopoverAnchor ref object of EmojiPickerButton, and the second .current is to access the emojiPopoverAnchor element of EmojiPickerButton (the Pressable)

Last, we need to modify below code so it pass the correct ref to the popover

anchorRef={emojiPopoverAnchor}

anchorRef={emojiPopoverAnchor.current ?? {}}

@melvin-bot melvin-bot bot added the Overdue label Nov 13, 2023
Copy link

melvin-bot bot commented Nov 13, 2023

@lschurr, @aimane-chnaif Whoops! This issue is 2 days overdue. Let's get this updated quick!

@aimane-chnaif
Copy link
Contributor

reviewing proposals

@melvin-bot melvin-bot bot removed the Overdue label Nov 13, 2023
@dragnoir
Copy link
Contributor

dragnoir commented Nov 13, 2023

Contributor details
Your Expensify account email: [email protected]
Upwork Profile Link: https://www.upwork.com/freelancers/rachidlajmi

Copy link

melvin-bot bot commented Nov 13, 2023

⚠️ Missing/invalid email or upwork profile link. Please make sure you add both your Expensify email and Upwork profile link in the format specified.

@dragnoir
Copy link
Contributor

Proposal

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

When resizing the window on the web browser, the open emoji picker moves to the LHN side.

What is the root cause of that problem?

The issue is exclusively observed in web browsers when users interact using a mouse. I conducted tests on a touchscreen device and encountered no problems. Further testing in Google Chrome's DevTools using the 'toggle device' option and responsive layout modes also did not reproduce the issue.

The specific problem arises when a user clicks the emoji button. This action triggers the addition of a background style to the anchor element in the DOM. Our calculateAnchorPosition function retrieves the emojiPopoverAnchor.current element, which includes this background style. However, by the time measureInWindow initiates its search for this element, the DOM has already updated to a version where the anchor no longer has the background style. This discrepancy is likely causing the issue we're observing.

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

To address the issue, we can implement a detection mechanism to ascertain if the user is interacting via a mouse. In scenarios where the window is being resized, we can strategically hide the Emoji Picker. This approach maintains the existing user experience on touchscreen devices, while effectively resolving the issue on desktops and laptops. By hiding the Emoji Picker during window resizing and only displaying it again upon user click, we ensure a seamless experience across different devices.

// state for user using a mouse
const [isUsingMouse, setIsUsingMouse] =  useState(false);

useEffect(() => {
	const  handleMouseMove  = () => {
		setIsUsingMouse(true);
		// Remove the event listener after detecting mouse movement
		window.removeEventListener('mousemove', handleMouseMove);
	};

	if (!isUsingMouse) {
		window.addEventListener('mousemove', handleMouseMove);
	}

	const  emojiPopoverDimensionListener  =  Dimensions.addEventListener('change', () => {
		if (isUsingMouse) {
			hideEmojiPicker();
		}
		// rest of the code ..
		return () => {
			emojiPopoverDimensionListener.remove();
			window.removeEventListener('mousemove', handleMouseMove);
	};
}, [isEmojiPickerVisible, isSmallScreenWidth, emojiPopoverAnchorOrigin]);

What alternative solutions did you explore? (Optional)

  • N/A

Copy link

melvin-bot bot commented Nov 13, 2023

📣 @dragnoir! 📣
Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
    Screen Shot 2022-11-16 at 4 42 54 PM
    Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

@dragnoir
Copy link
Contributor

Contributor details
Your Expensify account email: [email protected]
Upwork Profile Link: https://www.upwork.com/freelancers/rachidlajmi

Copy link

melvin-bot bot commented Nov 13, 2023

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

@dragnoir
Copy link
Contributor

dragnoir commented Nov 15, 2023

Proposal

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

When resizing the window on the web browser, the open emoji picker moves to the LHN side.

What is the root cause of that problem?

I was reviewing my last proposal and with more testing, it seems that I am wrong, it's not about the style on the DOM. I checked more about the element position and the best practice to it and I found that EmojiPickerButton is not structured the way it's recommanded for measureInWindow.
There's some rendering issues that prevent the function from getting the right anchor details.

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

The return of EmojiPickerButton.js should be embedded inside a view where the refs should be.

import {View} from  'react-native';

return (
	<View
		ref={emojiPopoverAnchor}
	>
		<Tooltip  text={props.translate('reportActionCompose.emoji')}>
			<PressableWithoutFeedback
	// rest of the code
			</PressableWithoutFeedback>
		</Tooltip>
	</View>
);

so moving ref={emojiPopoverAnchor} from PressableWithoutFeedback to the new View will solve the issue.

Video after the code update

browser_resize.mp4

What alternative solutions did you explore? (Optional)

  • N/A

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

lschurr commented Nov 15, 2023

@aimane-chnaif can you review the proposals here?

@melvin-bot melvin-bot bot removed the Overdue label Nov 15, 2023
Copy link

melvin-bot bot commented Nov 16, 2023

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

@aimane-chnaif
Copy link
Contributor

reviewing

@lschurr
Copy link
Contributor

lschurr commented Jan 12, 2024

Hi @aimane-chnaif @bernhardoj @neil-marcellini - Could someone take a look here and let me know how to proceed? Has the regression been fixed?

@melvin-bot melvin-bot bot removed the Overdue label Jan 12, 2024
@aimane-chnaif
Copy link
Contributor

not fixed yet

@melvin-bot melvin-bot bot added the Overdue label Jan 14, 2024
@lschurr
Copy link
Contributor

lschurr commented Jan 15, 2024

Any update @aimane-chnaif?

@melvin-bot melvin-bot bot removed the Overdue label Jan 15, 2024
@aimane-chnaif
Copy link
Contributor

PR is in review. Not yet in mergeable state

@melvin-bot melvin-bot bot added the Overdue label Jan 17, 2024
@neil-marcellini neil-marcellini added the Reviewing Has a PR in review label Jan 17, 2024
@melvin-bot melvin-bot bot removed the Overdue label Jan 17, 2024
@neil-marcellini
Copy link
Contributor

Yep, under review.

@melvin-bot melvin-bot bot added Weekly KSv2 and removed Daily KSv2 labels Jan 19, 2024
@melvin-bot melvin-bot bot changed the title [HOLD for payment 2024-01-04] [$500] Emoji - When resizing the window, the open emoji picker moves to the LHN side [HOLD for payment 2024-01-26] [HOLD for payment 2024-01-04] [$500] Emoji - When resizing the window, the open emoji picker moves to the LHN side Jan 19, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Jan 19, 2024
Copy link

melvin-bot bot commented Jan 19, 2024

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

Copy link

melvin-bot bot commented Jan 19, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.27-1 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-01-26. 🎊

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

Copy link

melvin-bot bot commented Jan 19, 2024

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@aimane-chnaif] The PR that introduced the bug has been identified. Link to the PR:
  • [@aimane-chnaif] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • [@aimane-chnaif] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
  • [@aimane-chnaif] Determine if we should create a regression test for this bug.
  • [@aimane-chnaif] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@lschurr] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@lschurr lschurr changed the title [HOLD for payment 2024-01-26] [HOLD for payment 2024-01-04] [$500] Emoji - When resizing the window, the open emoji picker moves to the LHN side [HOLD for payment 2024-01-26] [$500] Emoji - When resizing the window, the open emoji picker moves to the LHN side Jan 19, 2024
@lschurr
Copy link
Contributor

lschurr commented Jan 25, 2024

@aimane-chnaif - Can you work through the checklist on this one?

@aimane-chnaif
Copy link
Contributor

  • The PR that introduced the bug has been identified. Link to the PR: Add popover anchor tooltip #30150
  • The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment: https://github.com/Expensify/App/pull/30150/files#r1439823954
  • A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion: N/A
  • Determine if we should create a regression test for this bug. This is kind of edge case and caught by QA team so no need regression test
  • If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.

@lschurr
Copy link
Contributor

lschurr commented Jan 29, 2024

It looks like the automation didn't work here. Moving to Daily and will handle payments shortly.

@lschurr lschurr added Daily KSv2 and removed Weekly KSv2 labels Jan 29, 2024
@lschurr
Copy link
Contributor

lschurr commented Jan 30, 2024

Payment summary:

@lschurr
Copy link
Contributor

lschurr commented Jan 30, 2024

Offers sent in Upwork.

@aimane-chnaif
Copy link
Contributor

Offer accepted already - #31155 (comment)

@lschurr
Copy link
Contributor

lschurr commented Jan 30, 2024

Ah, sorry about that! I'll use the previous offers.

@lschurr
Copy link
Contributor

lschurr commented Jan 30, 2024

Payments issued. Closing this one out.

@lschurr lschurr closed this as completed Jan 30, 2024
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. Daily KSv2 Engineering Internal Requires API changes or must be handled by Expensify staff
Projects
None yet
Development

No branches or pull requests

10 participants