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
[$1000] Zoom view in the attachment preview is lost with 4 or more attachments #18614
BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributors
Navigate back 4 images and again navigate back to first image and observe that image is zoomed out
Repeat step 3 and 4 with 3 images in step 4 and observe that image is zoomed in
Expected Result:
App should remember zoomed in position throughout the attachment navigations as it does when we only navigate back 3 images
Actual Result:
Image is zoomed out when we navigate back 4 images in attachment preview
Workaround:
Can the user still use Expensify without this being fixed? Have you informed them of the workaround?
Platforms:
Which of our officially supported platforms is this issue occurring on?
Android / native
Android / Chrome
iOS / native
iOS / Safari
MacOS / Chrome / Safari
MacOS / Desktop
Version Number: 1.3.11.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 Notes/Photos/Videos: Any additional supporting documentation
Please re-state the problem that we are trying to solve in this issue.
Zoom gets reset after navigating 3 attachments before or after.
What is the root cause of that problem?
This isn't a bug, it's intended behaviour. To prevent devices from lagging/crashing it is limited to load three attachments at the same time, after which the furthest attachment gets unloaded to clear up cache. This is done using the maxToRenderPerBatch attribute in line 375 in the code shown below.
What changes do you think we should make in order to solve the problem?
To keep behaviour consistent, we could store data related to the state of the attachment (such as position, scroll, etc.) in an array. This way we can restore it's state when it's reloaded. For this an attribute (ex: initialState) can be created in the AttachmentView component to specify what the view should look like when initially loaded.
In our makeInitialState() function where we create an array of attachments, we also create a local variable to store attachment states.
Note: We don't need to store this in the react state because we only need to use it initially when the AttachmentView component mounts.
We then create a function to update this state whenever required.
/** * Updates the attachment state to restore it later * @param {Object} state current attachment state * @param {Number} index index of the attachment to update */updateAttachmentState(state,index){this.attachmentStates[index]=state;}
Our AttachmentView component will then look like this. These props will be then passed down to ImageView and PDFView.
And in the componentWillUnmount we use the this.props.onStateUpdate() function since it will only be required if the component is unmounted.
What alternative solutions did you explore? (Optional)
One solution would be to disable navigation while an attachment is zoomed in like WhatsApp does. For this we simply pass an onScaleChanged function prop to the AttachmentView component and further to the ImageView to call the updateZoomState() function in AttachmentCarousel which hides the arrows if zoom > 1. This is already done for touch devices only for PDF files.
Another solution would be to reset zoom if navigated to keep behaviour consistent. There are two ways to do this,
The first method involves creating a resetZoom() function in the ImageView component.
/** * Reset the image zoom, used by the AttachmentCarousel component. */resetZoom(){this.setState({isZoomed: false,isDragging: false,isMouseDown: false});}
We then pass down a ref from AttachmentCarousel -> AttachmentView -> ImageView.
After this we can access the resetZoom() function using this ref with the line below. This can be added to the updatePage() function in the setState() callback.
this.currentAttachment.current?.resetZoom();
The second method involves bring the zoom state from ImageView to AttachmentCarousel which I DO NOT recommend as it's just very messy.
A third method (I wound't really call it a method) in theory, would be to set maxToRenderPerBatch={1} 😅.
Looks like something related to react-navigation may have been mentioned in this issue discussion.
As a reminder, please make sure that all proposals are not workarounds and that any and all attempt to fix the issue holistically have been made before proceeding with a solution. Proposals to change our DeprecatedCustomActions.js files should not be accepted.
Will there be a case where the FlatList component ignores the windowSize prop due to lack of system resources, I feel there's a possibility of this so the application wouldn't crash.
While it's a valid consideration, it's important to note that the FlatList component isn't designed to manage system resources. Instead, it will simply attempt to perform the task we've specified. If we start to notice any performance degradation, it will be our responsibility to revisit and refine our solution accordingly.
2. This approach could slow down the system as more and more attachments are added especially if they are heavy. And again there may be a possibility that FlatList destroys attachments to prevent crashes.
Indeed, an excessive number of image attachments could pose a performance challenge. However, this would only be an issue if the user scrolls past hundreds of images. We can manage this effectively by setting an upper limit.
This boundary ensures that the window doesn't grow beyond a manageable size. While technically the issue could still occur, we have to ask: would a user realistically zoom into an attachment, scroll 100 attachments away, and then scroll back?
A potential complementary or standalone solution to the virtual window size could involve using react-freeze. This package preserves the component state while replacing off-screen items with a low-cost placeholder. It's a method we're already employing in a different part of the app.
We could render items outside the immediate view area as 'frozen' with the following:
renderItem({ item, index }){constdiff=Math.abs(index-this.state.page);if(diff>2)// return FreezedItemelse// return RegularItem}
This approach would ensure that off-screen items don't overly tax system resources while maintaining user experience continuity.
Hey @kidroca Thank you for clarifying the issue with the windowSize and for providing an alternative approach. Your suggestion of maintaining a Set of rendered items and dynamically adjusting the windowSize based on the number of rendered items is an interesting solution. The only concern is that we may have more memory consumption. I think we can limit the max windowSize to just 20 or maybe 10. It doesn’t looks realistic for a user to scroll 10 attachments away, and then scroll back and expects to get the maintained zoom state.
Thank you for the engaging and insightful discussion, @kidroca and @therealsujitk! 🙌🏼 . Taking into account the concerns raised, it prompts me to question whether addressing this issue is truly necessary. Upon evaluating the current behavior, it seems that the actual result is quite satisfactory. Users are experiencing a good and reasonable interaction, with the attachment state (including zoom and scroll position) being successfully preserved for the last 3 visited attachments.
I would appreciate hearing @MonilBhavsar's thoughts on this issue. Your input would be valuable in determining whether further action is required.
The only concern is that we may have more memory consumption. I think we can limit the max windowSize to just 20 or maybe 10. It doesn’t looks realistic for a user to scroll 10 attachments away, and then scroll back and expects to get the maintained zoom state.
Users are experiencing a good and reasonable interaction, with the attachment state (including zoom and scroll position) being successfully preserved for the last 3 visited attachments.
Well, I personally think it is fair to maintain zoomed state for last 3 visited attachments. cc Bug-zero team - @maddylewis@miljakljajic@michaelhaxhiu
If we agree, we can :donothing: and consider this as "a feature and not a bug"
@MonilBhavsar@fedirjh@maddylewis 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!
BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributors
Activity
melvin-bot commentedon May 8, 2023
Triggered auto assignment to @michaelhaxhiu (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.melvin-bot commentedon May 8, 2023
Bug0 Triage Checklist (Main S/O)
Platformsin OP are ✅)therealsujitk commentedon May 9, 2023
Proposal
Please re-state the problem that we are trying to solve in this issue.
Zoom gets reset after navigating 3 attachments before or after.
What is the root cause of that problem?
This isn't a bug, it's intended behaviour. To prevent devices from lagging/crashing it is limited to load three attachments at the same time, after which the furthest attachment gets unloaded to clear up cache. This is done using the
maxToRenderPerBatchattribute in line 375 in the code shown below.App/src/components/AttachmentCarousel/index.js
Lines 347 to 383 in bc8cc52
What changes do you think we should make in order to solve the problem?
To keep behaviour consistent, we could store data related to the state of the attachment (such as position, scroll, etc.) in an array. This way we can restore it's state when it's reloaded. For this an attribute (ex:
initialState) can be created in theAttachmentViewcomponent to specify what the view should look like when initially loaded.In our
makeInitialState()function where we create an array of attachments, we also create a local variable to store attachment states.We then create a function to update this state whenever required.
Our
AttachmentViewcomponent will then look like this. These props will be then passed down toImageViewandPDFView.Finally in the
ImageViewandPDFViewwe read the initial state in the constructor.And in the
componentWillUnmountwe use thethis.props.onStateUpdate()function since it will only be required if the component is unmounted.What alternative solutions did you explore? (Optional)
onScaleChangedfunction prop to theAttachmentViewcomponent and further to theImageViewto call theupdateZoomState()function inAttachmentCarouselwhich hides the arrows ifzoom > 1. This is already done for touch devices only for PDF files.The first method involves creating a
resetZoom()function in theImageViewcomponent.We then pass down a ref from
AttachmentCarousel->AttachmentView->ImageView.After this we can access the
resetZoom()function using this ref with the line below. This can be added to theupdatePage()function in thesetState()callback.The second method involves bring the zoom state from
ImageViewtoAttachmentCarouselwhich I DO NOT recommend as it's just very messy.A third method (I wound't really call it a method) in theory, would be to set
maxToRenderPerBatch={1}😅.melvin-bot commentedon May 9, 2023
Looks like something related to
react-navigationmay have been mentioned in this issue discussion.As a reminder, please make sure that all proposals are not workarounds and that any and all attempt to fix the issue holistically have been made before proceeding with a solution. Proposals to change our
DeprecatedCustomActions.jsfiles should not be accepted.Feel free to drop a note in #expensify-open-source with any questions.
melvin-bot commentedon May 9, 2023
Triggered auto assignment to @maddylewis (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.melvin-bot commentedon May 9, 2023
michaelhaxhiu commentedon May 9, 2023
small note: re-assigning as I'm OOO till next week
maddylewis commentedon May 9, 2023
i am OOO starting tomorrow but will try to repro this / push this along
43 remaining items
kidroca commentedon May 24, 2023
While it's a valid consideration, it's important to note that the FlatList component isn't designed to manage system resources. Instead, it will simply attempt to perform the task we've specified. If we start to notice any performance degradation, it will be our responsibility to revisit and refine our solution accordingly.
Indeed, an excessive number of image attachments could pose a performance challenge. However, this would only be an issue if the user scrolls past hundreds of images. We can manage this effectively by setting an upper limit.
This boundary ensures that the window doesn't grow beyond a manageable size. While technically the issue could still occur, we have to ask: would a user realistically zoom into an attachment, scroll 100 attachments away, and then scroll back?
A potential complementary or standalone solution to the virtual window size could involve using react-freeze. This package preserves the component state while replacing off-screen items with a low-cost placeholder. It's a method we're already employing in a different part of the app.
We could render items outside the immediate view area as 'frozen' with the following:
This approach would ensure that off-screen items don't overly tax system resources while maintaining user experience continuity.
fedirjh commentedon May 26, 2023
Hey @kidroca Thank you for clarifying the issue with the
windowSizeand for providing an alternative approach. Your suggestion of maintaining aSetof rendered items and dynamically adjusting thewindowSizebased on the number of rendered items is an interesting solution. The only concern is that we may have more memory consumption. I think we can limit the maxwindowSizeto just 20 or maybe 10. It doesn’t looks realistic for a user to scroll 10 attachments away, and then scroll back and expects to get the maintained zoom state.fedirjh commentedon May 26, 2023
Thank you for the engaging and insightful discussion, @kidroca and @therealsujitk! 🙌🏼 . Taking into account the concerns raised, it prompts me to question whether addressing this issue is truly necessary. Upon evaluating the current behavior, it seems that the actual result is quite satisfactory. Users are experiencing a good and reasonable interaction, with the attachment state (including zoom and scroll position) being successfully preserved for the last 3 visited attachments.
I would appreciate hearing @MonilBhavsar's thoughts on this issue. Your input would be valuable in determining whether further action is required.
melvin-bot commentedon May 26, 2023
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸
MonilBhavsar commentedon May 29, 2023
I agree with this 👍
MonilBhavsar commentedon May 29, 2023
Well, I personally think it is fair to maintain zoomed state for last 3 visited attachments. cc Bug-zero team - @maddylewis @miljakljajic @michaelhaxhiu
If we agree, we can :donothing: and consider this as "a feature and not a bug"
melvin-bot commentedon May 29, 2023
@MonilBhavsar @fedirjh @maddylewis 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!
maddylewis commentedon May 31, 2023
@MonilBhavsar - i think we can consider this a feature and not a bug!