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

Fix tapping on new messages after marking a message unread leads to a blank page #32630

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

wlegolas
Copy link
Contributor

@wlegolas wlegolas commented Dec 7, 2023

Details

This PR will fix the issue related to the displayed blank page when the user clicks on the "New messages" button before the scroll action ends.

Fixed Issues

$ #31591
PROPOSAL: #31591 (comment)

Tests

  1. Navigate to https://dev.new.expensify.com:8082
  2. Log in
  3. Open a group conversation with a lot of messages
  4. Swipe to the middle of the page and mark any message as unread
  5. Swipe to the top of the page
  6. Tap on the "New messages" button
  7. The user is redirected to the unread message.
  • Verify that no errors appear in the JS console

Offline tests

  1. Navigate to https://dev.new.expensify.com:8082
  2. Log in
  3. Open a group conversation with a lot of messages
  4. Turn off your network connection
  5. Swipe to the middle of the page and mark any message as unread
  6. Swipe to the top of the page
  7. Tap on the "New messages" button
  8. The user is redirected to the unread message.
  • Verify that no errors appear in the JS console

QA Steps

  1. Navigate to https://staging.new.expensify.com/
  2. Log in
  3. Open a group conversation with a lot of messages
  4. Swipe to the middle of the page and mark any message as unread
  5. Swipe to the top of the page
  6. Tap on the "New messages" button
  7. The user is redirected to the unread message.
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
evidence-Android-Native.mp4
Android: mWeb Chrome
evidence-Android-mWeb-Chrome.mp4
iOS: Native
evidence-iOS-Native.mp4
iOS: mWeb Safari
evidence-iOS-mWeb-Safari.mp4
MacOS: Chrome / Safari

Chrome

evidence-MacOS-Chrome.mp4

Safari

evidence-MacOS-Safari.mp4
MacOS: Desktop
evidence-MacOS-Desktop.mp4

@wlegolas wlegolas requested a review from a team as a code owner December 7, 2023 04:35
@melvin-bot melvin-bot bot requested review from parasharrajat and removed request for a team December 7, 2023 04:35
Copy link

melvin-bot bot commented Dec 7, 2023

@parasharrajat Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

onScroll(event);

if (isNative) {
Copy link
Contributor Author

@wlegolas wlegolas Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only call the handleUnreadFloatingButton for Native devices because the native InvertedFlatList doesn't have the implementation to handle the scroll events to call the onScrollEnd handler.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the issue we faced is present on mWeb then this check will prevent that fix. Right? Also, the scrollend implementation is done on web file(index.js) not on native (index.native.js) of InvertedFlatList.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is only used to have the same behavior (shows the "New message" button on scroll) for Native devices because there is no scroll implementation for the index.native.js file for InvetedFlatList.

I'll improve the index.native.js to use the scrolls mechanism instead of this isNative check.

};

const scrollToBottomAndMarkReportAsRead = () => {
reportScrollManager.scrollToBottom();
const scrollToUnreadMessageAndMarkReportAsRead = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make sure that the unread message is fully visible on the window.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the méthod reportScrollManager.scrollToIndex the behavior is to put on the bottom the unread message and the user can see all the message content.

I don't know if your suggestion is to scroll and show this unread message in a particular place on the screen, for example in the middle of the screen. If so, we need to improve the method reportScrollManager.scrollToIndex to receive the viewPosition (scrolltoindex) with a number that indicates the place we want to show this message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if your suggestion is to scroll and show this unread message in a particular place on the screen, for example in the middle of the screen. If so, we need to improve the method reportScrollManager.scrollToIndex to receive the viewPosition (scrolltoindex) with a number that indicates the place we want to show this message.

This is a good suggestion when there are multiple unread messages. so I would say let's leave that part for now. No added complexity.

Comment on lines 123 to 124
const platform = getPlatform();
const isNative = platform === CONST.PLATFORM.IOS || platform === CONST.PLATFORM.ANDROID;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't allow direct use of Platform API. Instead, use platform files (index.js or index.native.js etc).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood, I saw another component using this approach and I thought I could use the same approach.

I'll change the behavior for native using the index.native.js file.

@parasharrajat
Copy link
Member

Testing...

Comment on lines 26 to 83
useEffect(
() => () => {
if (!scrollEndTimeout.current) {
return;
}

clearTimeout(scrollEndTimeout.current);
},
[props.innerRef],
);

/**
* Emits when the scrolling is in progress. Also,
* invokes the onScroll callback function from props.
*
* @param {Event} event - The onScroll event from the FlatList
*/
const onScroll = (event) => {
props.onScroll(event);
};

/**
* Emits when the scrolling has ended. Also,
* invokes the onScrollEnd callback function from props.
*/
const onScrollEnd = () => {
props.onScrollEnd();
};

/**
* Decides whether the scrolling has ended or not. If it has ended,
* then it calls the onScrollEnd function. Otherwise, it calls the
* onScroll function and pass the event to it.
*
* @param {Event} event - The onScroll event from the FlatList
*/
const handleScroll = (event) => {
onScroll(event);

const timestamp = Date.now();

// console.log('=> handleScroll', {timestamp, 'lastScrollEvent.current': lastScrollEvent.current})

if (scrollEndTimeout.current) {
clearTimeout(scrollEndTimeout.current);
}

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

lastScrollEvent.current = timestamp;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this logic same on both native and web file so we should move this to BaseInvertedFlatList

Copy link
Contributor Author

@wlegolas wlegolas Dec 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please review this commit 590666a please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @parasharrajat if you have any questions or suggestions, please let me know.

const scrollToUnreadMessageAndMarkReportAsRead = () => {
const scrollIndex = getScrollIndex();

isUnreadMessageFocused.current = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain the purpose of this flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flag is used to avoid showing the "New Message" button when the scroll ends after the user clicks the "New Message" button.

When the user clicks on the "New Message" button the scroll occurs and we don't need to show again the "New Message" button because this current scroll was triggered by the "New Message" button action.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I think you tried you mimic Slack behaviour but it is still different from slack. On Slack, when an unread message is visible on the screen marker remains hidden.

@parasharrajat
Copy link
Member

@wlegolas Can you please merge main?

@wlegolas
Copy link
Contributor Author

wlegolas commented Dec 27, 2023

@wlegolas Can you please merge main?

Sure, I updated my branch with the main branch. I tested again and It seems like everything is working as expected.

@parasharrajat
Copy link
Member

parasharrajat commented Dec 28, 2023

Please use merge commit instead of force push. For now, we are fine on this PR.

@wlegolas
Copy link
Contributor Author

wlegolas commented Jan 2, 2024

Hi @parasharrajat I resolved a conflict in the BaseInvertedFlatList because this component was migrated to TypeScript from this Pull Request #33288

If you have any questions, please let me know.

@wlegolas
Copy link
Contributor Author

wlegolas commented Jan 2, 2024

I saw the Unit Test step is failing, but this problem is occurring on the main branch, if I see a commit with the fix, I'll do another merge to check this step.

image


const AUTOSCROLL_TO_TOP_THRESHOLD = 128;
const WINDOW_SIZE = 15;

function BaseInvertedFlatList<T>(props: FlatListProps<T>, ref: ForwardedRef<FlatList>) {
function BaseInvertedFlatList<T>({onScroll: onScrollProp = () => {}, onScrollEnd: onScrollEndProp = () => {}, ...props}: InvertedFlatListProps<T>, ref: ForwardedRef<FlatList>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to give inline type when have already defined that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to ask @parasharrajat I didn't understand. Do you mean to not give inline type onScrollProp?

* onScroll function and pass the event to it.
*
* This is a temporary work around, since react-native-web doesn't
* support onScrollBeginDrag and onScrollEndDrag props for FlatList.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think native has this method so we should use those instead for the native part.

Comment on lines 9 to 12
function InvertedFlatList<T>(
{onScroll: onScrollProp = () => {}, onScrollEnd: onScrollEndProp = () => {}, contentContainerStyle, ...props}: InvertedFlatListProps<T>,
ref: ForwardedRef<FlatList>,
) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the previous comment.

const scrollToUnreadMessageAndMarkReportAsRead = () => {
const scrollIndex = getScrollIndex();

isUnreadMessageFocused.current = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I think you tried you mimic Slack behaviour but it is still different from slack. On Slack, when an unread message is visible on the screen marker remains hidden.

@parasharrajat
Copy link
Member

I am not sure if we want to mimic Slack behavior. Also, this is a big decision to make. If we find this idle then we will have to propose this on Slack first.

I tested your branch and there are a few issues. I will post them here after I am done.

@wlegolas
Copy link
Contributor Author

wlegolas commented Jan 2, 2024

I am not sure if we want to mimic Slack behavior. Also, this is a big decision to make. If we find this idle then we will have to propose this on Slack first.

I tested your branch and there are a few issues. I will post them here after I am done.

I'm not trying to mimic Slack behavior, just trying to bring the behavior to the "New message" button closes that the behavior we know from Slack, but you're right, we need to propose to the Expensify team.

In my opinion, for this issue, we only need to know which is the expected result when there is a new message, I just putting this behavior because for me makes sense to show the "New message" button when there is a new message and the scroll ends.

But I'm totally open to hearing your suggestion

@parasharrajat
Copy link
Member

parasharrajat commented Jan 17, 2024

Reviewing...

@wlegolas
Copy link
Contributor Author

Hi @parasharrajat do you have updates about your review process?

@parasharrajat
Copy link
Member

@wlegolas Please merge the main when you get time. Thanks for waiting.

@wlegolas
Copy link
Contributor Author

wlegolas commented Feb 6, 2024

@wlegolas Please merge the main when you get time. Thanks for waiting.

Hi @parasharrajat I merged the main into my branch, I did some tests and the implementation is working as expected.

If you need anything else, please let me know.

@wlegolas
Copy link
Contributor Author

Hi @parasharrajat did you have time to review my PR?

@parasharrajat
Copy link
Member

I have been OOO since 10 days. I was about to grt back but something came up. I will try to get this tomorrow. I started the analysis before going OOO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants