Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.57k stars 2.91k forks source link

[$250] Attachments - Attachment preview slides to the right with a delay when dismissed #52937

Open lanitochka17 opened 3 days ago

lanitochka17 commented 3 days ago

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.0.65-3 Reproducible in staging?: Y Reproducible in production?: Y If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: Y If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/5249444 Issue reported by: Applause - Internal Team

Action Performed:

  1. Launch staging new.expensify Hybrid app and sign in
  2. Open 1:1 chat with variety of attachments sent
  3. Tap on attachment preview to open larger preview
  4. Tap < button on the left side of the preview to navigate back to the chat
  5. Repeat with a few other attachments

Expected Result:

Attachment preview can be dismissed without delay

Actual Result:

Attachment preview slides to the right with a delay when dismissed. Part of the current attachment followed by previously opened attachment can be seen for a couple of seconds on the right side of the screen

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Add any screenshot/video evidence

https://github.com/user-attachments/assets/5495074b-2e9b-46ab-939a-0a589efd92b2

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021859724558833397121
  • Upwork Job ID: 1859724558833397121
  • Last Price Increase: 2024-11-21
Issue OwnerCurrent Issue Owner: @thesahindia
melvin-bot[bot] commented 3 days ago

Triggered auto assignment to @trjExpensify (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.

trjExpensify commented 3 days ago

I can repro this:

https://github.com/user-attachments/assets/f45c17ce-e467-4150-af72-3ffd8c555af6

melvin-bot[bot] commented 3 days ago

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

melvin-bot[bot] commented 3 days ago

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

huult commented 2 days ago

Edited by proposal-police: This proposal was edited at 2024-11-22 07:32:34 UTC.

Proposal

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

Attachment preview slides to the right with a delay when dismissed

What is the root cause of that problem?

The modal dismissal was triggered before the attachment carousel animation completed. This caused a conflict between the animation lifecycle and modal dismissal, leading to visual inconsistencies.

https://github.com/Expensify/App/blob/5e2d95a6aaa5bd100c4c1e2e4b991fc05ba0e11d/src/pages/home/report/ReportAttachments.tsx#L54

https://github.com/Expensify/App/blob/f5e8d3e97489118e5daf53af043f35ba5935801a/src/components/Attachments/AttachmentCarousel/index.tsx#L294

This happens only on iOS native because its native modal animations run concurrently with Animated.FlatList, leading to conflicts. iOS enforces stricter rendering and animation synchronization, exposing timing issues.

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

To resolve this issue, we must delay dismissing the modal until the animation of the attachment carousel is completed. This ensures that all active interactions, including animations and gestures, are finished before the modal is dismissed, avoiding conflicts between the animation lifecycle and modal dismissal. Something like this:

//src/pages/home/report/ReportAttachments.tsx#L55
       <AttachmentModal
            accountID={Number(accountID)}
            type={type}
            allowDownload
            defaultOpen
            report={report}
            source={source}
            onModalClose={() => {
+                InteractionManager.runAfterInteractions(() => {
+                    requestAnimationFrame(() => {
                        Navigation.dismissModal();
                        // This enables Composer refocus when the attachments modal is closed by the browser navigation
                        ComposerFocusManager.setReadyToFocus();
+                    });
+                });
            }}
            onCarouselAttachmentChange={onCarouselAttachmentChange}
            shouldShowNotFoundPage={!isLoadingApp && type !== CONST.ATTACHMENT_TYPE.SEARCH && !report?.reportID}
            isAuthTokenRequired={!!isAuthTokenRequired}
            attachmentLink={attachmentLink ?? ''}
            originalFileName={fileName ?? ''}
        />

Note: We can write this code specifically for iOS using Platform.OS === 'ios' or by creating an index.ios.ts file. We will discuss and implement this approach during the PR phase

POC https://github.com/user-attachments/assets/d2b2b0ac-0f16-426c-ac0f-18f5bd359ac4

What alternative solutions did you explore? (Optional)

daledah commented 2 days ago

Proposal

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

Attachment preview slides to the right with a delay when dismissed. Part of the current attachment followed by previously opened attachment can be seen for a couple of seconds on the right side of the screen

What is the root cause of that problem?

When pressing back button:

https://github.com/Expensify/App/blob/056e8ee563b1136ba5749988d89723fad467c7fd/src/pages/home/report/ReportAttachments.tsx#L53-L57

AttachmentModal is closed before AttachmentCarousel finishes unmounting, which causes visual bug.

The same bug appears on TransactionReceiptPage as well:

https://github.com/user-attachments/assets/97ba5a7d-356b-4d13-b9f4-6f2cb14bba22

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

Wrap onModalClose function with InteractionManager.runAfterInteractions:

https://github.com/Expensify/App/blob/056e8ee563b1136ba5749988d89723fad467c7fd/src/pages/home/report/ReportAttachments.tsx#L53-L57

            onModalClose={() => {
                InteractionManager.runAfterInteractions(() => {
                    Navigation.dismissModal();
                    // This enables Composer refocus when the attachments modal is closed by the browser navigation
                    ComposerFocusManager.setReadyToFocus();
                });
            }}

Apply the same for TransactionReceiptPage as well:

https://github.com/Expensify/App/blob/056e8ee563b1136ba5749988d89723fad467c7fd/src/pages/TransactionReceiptPage.tsx#L78

            onModalClose={() => {
                InteractionManager.runAfterInteractions(() => {
                    onModalClose();
                });
            }}

What alternative solutions did you explore? (Optional)

thesahindia commented 2 days ago

@huult's proposal is first but @daledah's proposal is also fixing another similar case. I will leave the decision to the engineer on this.

🎀 👀 🎀 C+ reviewed

melvin-bot[bot] commented 2 days ago

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