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: only dismiss the report attachment modal once #47622

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/pages/home/report/ReportAttachments.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useCallback} from 'react';
import React, {useCallback, useEffect} from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import React, {useCallback, useEffect} from 'react';
import React, {useCallback, useEffect, useRef} from 'react';

import {useOnyx} from 'react-native-onyx';
import AttachmentModal from '@components/AttachmentModal';
import type {Attachment} from '@components/Attachments/types';
Expand All @@ -18,6 +18,14 @@ function ReportAttachments({route}: ReportAttachmentsProps) {
const accountID = route.params.accountID;
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID || -1}`);
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP);
const hasDismissedModalRef = React.useRef(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const hasDismissedModalRef = React.useRef(false);
const hasDismissedModalRef = useRef(false);

Was there any reason why you didn't import the useRef ? LMK if that was on purpose, I didn't understand the motive here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@allgandalf sorry, maybe the code completion cause this. Fixed in the latest commit

Copy link
Contributor

Choose a reason for hiding this comment

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

haha, no worries, happens on best of our days 😄


useEffect(
() => () => {
hasDismissedModalRef.current = false;
},
[],
);

// In native the imported images sources are of type number. Ref: https://reactnative.dev/docs/image#imagesource
const source = Number(route.params.source) || route.params.source;
Expand All @@ -39,7 +47,10 @@ function ReportAttachments({route}: ReportAttachmentsProps) {
report={report}
source={source}
onModalClose={() => {
Navigation.dismissModal();
if (!hasDismissedModalRef.current) {
Navigation.dismissModal();
hasDismissedModalRef.current = true;
}
// This enables Composer refocus when the attachments modal is closed by the browser navigation
ComposerFocusManager.setReadyToFocus();
}}
Expand Down
Loading