You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[$500] mWeb/Safari - Chat - After removing an emoji and adding a new, the focus shifts the top of the page #31594
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
Version Number: 1.4.1.4 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:
Edit this message, remove the last emoji and add a new one
Expected Result:
The focus should stay on the edited message
Actual Result:
After removing an emoji and adding a new, the focus shifts to the top of the page and it shakes once.
On prod, the focus only moves up a little bit and the shake isn't present
Workaround:
Unknown
Platforms:
Which of our officially supported platforms is this issue occurring on?
changed the title [-]mWeb/Safari - Chat - After removing an emoji and adding a new, the focus shifts the top of the page[/-][+][$500] mWeb/Safari - Chat - After removing an emoji and adding a new, the focus shifts the top of the page[/+]on Nov 20, 2023
Please re-state the problem that we are trying to solve in this issue.
mWeb/Safari - Chat - After removing an emoji and adding a new, the focus shifts the top of the page
What is the root cause of that problem?
When the user edits a comment and opens the Emoji picker, closes this picker (selecting one emoji or just clicking outside of the picker), and saves the comment, the Flatlist calculates its height according to the current view, at this moment the Composer component is hidden and the Flatlist calculates its height without the space where Composer should be visible. That is the reason the scroll changed when finishing the comment edition because the difference in pixels between the scroll before and after editing the comment is equal to the Compose's height.
When finishing the edition, the method deleteDraft is called to act to draft the comment being edited. In this method, there is a condition to check if the user is editing the last message, if so, an event listener will be added to monitoring the event keyboardDidHide in the Keyboard object. But adding an event listener to the Keyboard object will only work on native devices, in this case, we are using a Mobile Browser.
What changes do you think we should make in order to solve the problem?
We should change the method deleteDraft in the ReportActionItemMessageEdit component to call the method ComposerActions.setShouldShowComposeInput passing the value true to show the ReportActionCompose before updating the Onyx state with an empty draft message.
Showing the Composer component before updating the Onyx state will keep the scroll inside the Flatlist in the current position because now the Flatlist will calculate its height without the Composer height.
For example,
/** * Delete the draft of the comment being edited. This will take the comment out of "edit mode" with the old content. */constdeleteDraft=useCallback(()=>{InputFocus.callback(()=>setIsFocused(false));InputFocus.inputFocusChange(false);debouncedSaveDraft.cancel();ComposerActions.setShouldShowComposeInput(true);// <- Here we should show the ComponseReport.saveReportActionDraft(props.reportID,props.action,'');if(isActive()){ReportActionComposeFocusManager.clear();ReportActionComposeFocusManager.focus();}// Scroll to the last comment after editing to make sure the whole comment is clearly visible in the report.if(props.index===0){constkeyboardDidHideListener=Keyboard.addListener('keyboardDidHide',()=>{reportScrollManager.scrollToIndex(props.index,false);keyboardDidHideListener.remove();});}},[props.action,debouncedSaveDraft,props.reportID,isActive]);
Note: There is a delay setTimeout just to wait for the Report Screen to be updated.
What alternative solutions did you explore? (Optional)
Hi @hoangzinh thank you for reviewing my proposal.
About your question, In my analysis, I understood the problem is only related when we edit the message and add a new emoji because when the emoji modal is shown the component's height changes and the position changes in the scroll view.
If you edit the emoji only removing information and saving you'll see that the strange behavior won't occur but if you edit the emoji removing and adding another one, the strange behavior will occur. In the video below you can see when the emoji modal opens in the messages in the background change their position.
When props.index === 0, scrollToIndex() is called too soon and doesn't have any effect in scrolling the edited comment into the viewport - the scroll view jumps to the top of the scroll list.
In the code block above we have logic for scrolling to the latest comment upon editing but this does not account for editing a message that is at an index different than 0, which is the case with this issue because we're editing a previous comment that's higher in the report.
The fact that we don't account for props.index !== 0 to scroll to the message, and also the fact that after editing and saving message the app sometimes toggles list refresh, any of these two or each separately, will make the scroll jump up and hide part of the conversation.
What changes do you think we should make in order to solve the problem?
Since the expected behaviour isn't clear as to where we want to position the scroll with regards to the just edited comment, here's what I propose:
My solution relies on using react native's flatlist scrollToIndex() method's viewPosition prop in our existing implementation of useReportScrollManager() -> scrollToIndex() so that we can pass one of the 3 values 0, 0.5 or 1 to scroll the view focusing the edited comment according to the following schema:
viewPosition: 0 - this will scroll the view such that edited comment is the last in the scrolled view (latest message of report will likely be hidden lower in scroll view)
viewPosition: 0.5 - this will scroll the view such that edited comment is in the middle the view (latest message of report will likely be hidden lower in scroll view)
viewPosition: 1 - this will scroll the view such that edited comment is at the top of the view (latest message of report will likely be seen if there's not a lot of of messages between last and edited comments OR will likely be hidden lower in scroll view if there are a lot of messages between the last and the edited message)
Say in this case if we decide to go with the viewPosition: 1 value, the result can be observed below for the 2nd problem mentioned in RCA.
For both the first and second problems from RCA to be fixed we need to delay calling scrollToIndex() with some form of timeout in order for the scroll to be effective.
@hoangzinh@CortneyOfstad this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!
@wlegolas your solution doesn't work if we're editing a comment that is not the last comment. I.e before the last comment
I think we should step back and understand clearly the root cause first, I also reproduced the issue with
Editing a text comment only
Then click open Emoji
Then close Emoji modal
Click save
Hi @hoangzinh you're right, if we follow your steps above the problem will occur. Sorry for not giving a solution before with the fix for this behavior I focused only on the current behavior when editing the last comment and adding a new emoji.
I could have the same problem following the steps above in my local, here's a video with the behavior.
issue-31594-wrong-behavior.mp4
In my proposal, I said in the alternative solutions section that we can use the method setShouldShowComposeInput from the ComposerActions to show the composer component before the Flatlist calculates its height, but in my proposal was only related to the last comment.
I'll update my proposal to call the method setShouldShowComposeInput before saving the Report draft. We can fix this behavior for any comment in the Flatlist with this change.
ah yeah @CortneyOfstad. Sorry everyone, this issue is not easy. I took time to go through each proposals and try to understand them. Gonna put updates soon.
@ikevin127 Thanks for your proposal. I don't think your RCA is correct. I tried to edit a message that is at an index different than 0 with text only, this bug does not occur.
@wlegolas@ikevin127 I believe this bug happens only in mWeb Safari. Both of your proposals haven't explained why it happens only in mWeb Safari, but not mWeb Chrome.
@hoangzinh@CortneyOfstad this issue is now 3 weeks old. There is one more week left before this issue breaks WAQ and will need to go internal. What needs to happen to get a PR in review this week? Please create a thread in #expensify-open-source to discuss. Thanks!
I don't think your RCA is correct. I tried to edit a message that is at an index different than 0 with text only, this bug does not occur.
The catch is to open the Emoji picker, as soon as you do that and save the edited comment, the scroll jumps - you don't even need to change anything while editing the comment, just opening the emoji picker is enough to make the scroll jump upon saving the edited comment when the FlatList layout size is updated.
I believe this bug happens only in mWeb Safari. Both of your proposals haven't explained why it happens only in mWeb Safari, but not mWeb Chrome.
It does happen on Chrome too, not just Safari. I tried with both real device and simulator and it's consistent between browsers.
To be more specific on what causes the scroll to jump:
Flatlist / emoji picker interactions
_
In React Native, a FlatList component uses a ScrollView internally to manage its layout and scrolling. When an external component like the emoji picker modal appears and is later closed, here's a high-level overview of what happens:
Modal Presentation: When the emoji picker modal is presented, especially if it's a half-screen modal that hovers above the main content, it typically does not immediately affect the underlying FlatList scrolling position. The modal is overlaid on top of the current screen's content, and as such, the FlatList sits in the background unaltered.
Layout Change: If the modal affects the layout by displacing or resizing the main content (such as when triggering adjustments for the virtual keyboard), this can disrupt the layout of FlatList. For example, the keyboard appearing typically causes the screen to resize to fit the remaining space, which would trigger a layout change on the FlatList.
Content Offset Preservation: React Native's ScrollView (and by extension FlatList) normally tries to preserve the content offset when a layout change occurs. In other words, it endeavors to keep the same content in view despite the change in screen real estate. However, this isn't always perfect, especially if the size of the items in the list changes or the list is dynamically loaded.
Modal Dismissal: Once a modal is dismissed, any previously applied layout constraints are removed. If the modal presented the keyboard and this affects the FlatList, dismissing the modal and hiding the keyboard would trigger another layout change as the screen returns to its full height. The FlatList would attempt to restore the scroll position as it was before the modal was presented.
Potential Scroll Issues: Despite React Native's efforts to preserve scroll position, there can be cases where the scroll position "jumps" or doesn't return exactly to the previous state. This behavior can be due to a number of factors, including dynamic content resizing, incomplete state updates before the layout change, or asynchronous events like network loads that alter the list content during the layout transition.
Considering all these, we also have the focus / blur of the edit composer which when emoji modal is opened from the edit composer, the composer is blurred which causes the main report composer to be rendered back into the FlatList, and when closing the emoji picker the edit composer focuses again which causes the main report composer to hide then when saving the edited comment, the main report composer to be rendered back into the FlatList again.
So lots of layout changes within the Flatlist but the main culprit is the emoji picker.
React Native FlatList doesn't have built-in specific handling for when modals appear or disappear; it simply responds to the resulting layout changes. If encountering scroll position issues after an emoji picker modal is dismissed, we may need to manually handle scroll position preservation and restoration, often involving setting variables that track necessary offsets or selected item indices and then executing scroll actions at appropriate times within the component lifecycle.
_
Hey! Sorry for the confusion here, but we just got an internal update. Per this post, we can close any bugs that are not related to Waves, so closing this out 👍 We will re-address once the waves are completed.
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
Activity
[-]mWeb/Safari - Chat - After removing an emoji and adding a new, the focus shifts the top of the page[/-][+][$500] mWeb/Safari - Chat - After removing an emoji and adding a new, the focus shifts the top of the page[/+]melvin-bot commentedon Nov 20, 2023
Triggered auto assignment to @CortneyOfstad (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.melvin-bot commentedon Nov 20, 2023
Job added to Upwork: https://www.upwork.com/jobs/~0124d5bed6c31044e5
melvin-bot commentedon Nov 20, 2023
Bug0 Triage Checklist (Main S/O)
Platformsin OP are ✅)melvin-bot commentedon Nov 20, 2023
Triggered auto assignment to Contributor-plus team member for initial proposal review - @hoangzinh (
External)wlegolas commentedon Nov 21, 2023
Proposal
Please re-state the problem that we are trying to solve in this issue.
mWeb/Safari - Chat - After removing an emoji and adding a new, the focus shifts the top of the page
What is the root cause of that problem?
When the user edits a comment and opens the Emoji picker, closes this picker (selecting one emoji or just clicking outside of the picker), and saves the comment, the
Flatlistcalculates its height according to the current view, at this moment theComposercomponent is hidden and theFlatlistcalculates its height without the space whereComposershould be visible. That is the reason the scroll changed when finishing the comment edition because the difference in pixels between the scroll before and after editing the comment is equal to the Compose's height.When finishing the edition, the method
deleteDraftis called to act to draft the comment being edited. In this method, there is a condition to check if the user is editing the last message, if so, an event listener will be added to monitoring the eventkeyboardDidHidein theKeyboardobject. But adding an event listener to theKeyboardobject will only work on native devices, in this case, we are using a Mobile Browser.App/src/pages/home/report/ReportActionItemMessageEdit.js
Lines 297 to 302 in 72e73ae
What changes do you think we should make in order to solve the problem?
We should change the method
deleteDraftin theReportActionItemMessageEditcomponent to call the methodComposerActions.setShouldShowComposeInputpassing the valuetrueto show theReportActionComposebefore updating the Onyx state with an empty draft message.Showing the
Composercomponent before updating the Onyx state will keep the scroll inside the Flatlist in the current position because now the Flatlist will calculate its height without theComposerheight.For example,
Note: There is a delay
setTimeoutjust to wait for the Report Screen to be updated.What alternative solutions did you explore? (Optional)
N/A
POC
issue-31594-with-fix.mp4
hoangzinh commentedon Nov 22, 2023
@wlegolas Thanks for your proposal. In your RCA, do you know why this issue is only reproducible with emoji only, but not text messages?
wlegolas commentedon Nov 22, 2023
Hi @hoangzinh thank you for reviewing my proposal.
About your question, In my analysis, I understood the problem is only related when we edit the message and add a new emoji because when the emoji modal is shown the component's height changes and the position changes in the scroll view.
If you edit the emoji only removing information and saving you'll see that the strange behavior won't occur but if you edit the emoji removing and adding another one, the strange behavior will occur. In the video below you can see when the emoji modal opens in the messages in the background change their position.
evidence-component-height.mp4
12 remaining items
melvin-bot commentedon Dec 4, 2023
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸
ikevin127 commentedon Dec 4, 2023
My proposal from #32217 issue which I'm pretty sure has the same RC.
Proposal
Please re-state the problem that we are trying to solve in this issue
After editing comment emoji by adding adding a new, the scroll view shifts to the top of the page and it shakes once.
What is the root cause of that problem?
App/src/pages/home/report/ReportActionItemMessageEdit.js
Lines 299 to 306 in 9bbb8ec
We have 2 problems:
When
props.index === 0,scrollToIndex()is called too soon and doesn't have any effect in scrolling the edited comment into the viewport - the scroll view jumps to the top of the scroll list.In the code block above we have logic for scrolling to the latest comment upon editing but this does not account for editing a message that is at an index different than 0, which is the case with this issue because we're editing a previous comment that's higher in the report.
The fact that we don't account for
props.index !== 0to scroll to the message, and also the fact that after editing and saving message the app sometimes toggles list refresh, any of these two or each separately, will make the scroll jump up and hide part of the conversation.What changes do you think we should make in order to solve the problem?
Since the expected behaviour isn't clear as to where we want to position the scroll with regards to the just edited comment, here's what I propose:
My solution relies on using react native's flatlist
scrollToIndex()method'sviewPositionprop in our existing implementation ofuseReportScrollManager()->scrollToIndex()so that we can pass one of the 3 values0,0.5or1to scroll the view focusing the edited comment according to the following schema:viewPosition - Values schema
The idea is that if we do:
viewPosition: 0- this will scroll the view such that edited comment is the last in the scrolled view (latest message of report will likely be hidden lower in scroll view)viewPosition: 0.5- this will scroll the view such that edited comment is in the middle the view (latest message of report will likely be hidden lower in scroll view)viewPosition: 1- this will scroll the view such that edited comment is at the top of the view (latest message of report will likely be seen if there's not a lot of of messages between last and edited comments OR will likely be hidden lower in scroll view if there are a lot of messages between the last and the edited message)Say in this case if we decide to go with the
viewPosition: 1value, the result can be observed below for the 2nd problem mentioned in RCA.For both the first and second problems from RCA to be fixed we need to delay calling
scrollToIndex()with some form of timeout in order for the scroll to be effective.Video from #32217
iOS: mWeb Safari
Screen.Recording.2023-11-30.at.16.47.27.mov
melvin-bot commentedon Dec 4, 2023
@hoangzinh @CortneyOfstad this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!
wlegolas commentedon Dec 5, 2023
I could have the same problem following the steps above in my local, here's a video with the behavior.
issue-31594-wrong-behavior.mp4
In my proposal, I said in the alternative solutions section that we can use the method
setShouldShowComposeInputfrom theComposerActionsto show the composer component before the Flatlist calculates its height, but in my proposal was only related to the last comment.I'll update my proposal to call the method
setShouldShowComposeInputbefore saving the Report draft. We can fix this behavior for any comment in the Flatlist with this change.issue-31594-with-fix.mp4
wlegolas commentedon Dec 5, 2023
Proposal
Updated
CortneyOfstad commentedon Dec 6, 2023
@hoangzinh thoughts on the proposals above ^^^? Thanks!
hoangzinh commentedon Dec 7, 2023
ah yeah @CortneyOfstad. Sorry everyone, this issue is not easy. I took time to go through each proposals and try to understand them. Gonna put updates soon.
hoangzinh commentedon Dec 10, 2023
@ikevin127 Thanks for your proposal. I don't think your RCA is correct. I tried to edit
a message that is at an index different than 0with text only, this bug does not occur.Screen.Recording.2023-12-10.at.20.30.35.mov
hoangzinh commentedon Dec 10, 2023
@wlegolas @ikevin127 I believe this bug happens only in mWeb Safari. Both of your proposals haven't explained why it happens only in mWeb Safari, but not mWeb Chrome.
Screen.Recording.2023-12-10.at.20.12.10.mov
melvin-bot commentedon Dec 11, 2023
@hoangzinh @CortneyOfstad this issue is now 3 weeks old. There is one more week left before this issue breaks WAQ and will need to go internal. What needs to happen to get a PR in review this week? Please create a thread in #expensify-open-source to discuss. Thanks!
melvin-bot commentedon Dec 11, 2023
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸
ikevin127 commentedon Dec 11, 2023
The catch is to open the Emoji picker, as soon as you do that and save the edited comment, the scroll jumps - you don't even need to change anything while editing the comment, just opening the emoji picker is enough to make the scroll jump upon saving the edited comment when the
FlatListlayout size is updated.It does happen on Chrome too, not just Safari. I tried with both real device and simulator and it's consistent between browsers.
To be more specific on what causes the scroll to jump:
Flatlist / emoji picker interactions
_
In React Native, a
FlatListcomponent uses aScrollViewinternally to manage its layout and scrolling. When an external component like the emoji picker modal appears and is later closed, here's a high-level overview of what happens:Modal Presentation: When the emoji picker modal is presented, especially if it's a half-screen modal that hovers above the main content, it typically does not immediately affect the underlying
FlatListscrolling position. The modal is overlaid on top of the current screen's content, and as such, theFlatListsits in the background unaltered.Layout Change: If the modal affects the layout by displacing or resizing the main content (such as when triggering adjustments for the virtual keyboard), this can disrupt the layout of
FlatList. For example, the keyboard appearing typically causes the screen to resize to fit the remaining space, which would trigger a layout change on theFlatList.Content Offset Preservation: React Native's
ScrollView(and by extensionFlatList) normally tries to preserve the content offset when a layout change occurs. In other words, it endeavors to keep the same content in view despite the change in screen real estate. However, this isn't always perfect, especially if the size of the items in the list changes or the list is dynamically loaded.Modal Dismissal: Once a modal is dismissed, any previously applied layout constraints are removed. If the modal presented the keyboard and this affects the
FlatList, dismissing the modal and hiding the keyboard would trigger another layout change as the screen returns to its full height. TheFlatListwould attempt to restore the scroll position as it was before the modal was presented.Potential Scroll Issues: Despite React Native's efforts to preserve scroll position, there can be cases where the scroll position "jumps" or doesn't return exactly to the previous state. This behavior can be due to a number of factors, including dynamic content resizing, incomplete state updates before the layout change, or asynchronous events like network loads that alter the list content during the layout transition.
Considering all these, we also have the focus / blur of the edit composer which when emoji modal is opened from the edit composer, the composer is blurred which causes the main report composer to be rendered back into the
FlatList, and when closing the emoji picker the edit composer focuses again which causes the main report composer to hide then when saving the edited comment, the main report composer to be rendered back into theFlatListagain.So lots of layout changes within the
Flatlistbut the main culprit is the emoji picker.React Native FlatList doesn't have built-in specific handling for when modals appear or disappear; it simply responds to the resulting layout changes. If encountering scroll position issues after an emoji picker modal is dismissed, we may need to manually handle scroll position preservation and restoration, often involving setting variables that track necessary offsets or selected item indices and then executing scroll actions at appropriate times within the component lifecycle.
_
CortneyOfstad commentedon Dec 12, 2023
Hey! Sorry for the confusion here, but we just got an internal update. Per this post, we can close any bugs that are not related to Waves, so closing this out 👍 We will re-address once the waves are completed.