From fd42a447dd25a78473b4480db820f65b09bf22ae Mon Sep 17 00:00:00 2001 From: dominictb Date: Tue, 17 Sep 2024 15:53:28 +0700 Subject: [PATCH 1/2] fix: keyboard overlaps pdf error modal --- src/components/AttachmentModal.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/AttachmentModal.tsx b/src/components/AttachmentModal.tsx index c327d7fa6093..839cd608a853 100644 --- a/src/components/AttachmentModal.tsx +++ b/src/components/AttachmentModal.tsx @@ -494,10 +494,11 @@ function AttachmentModal({ setShouldLoadAttachment(true); }} onModalHide={() => { - onModalHide(); + if (!isPDFLoadError.current) { + onModalHide(); + } setShouldLoadAttachment(false); if (isPDFLoadError.current) { - isPDFLoadError.current = false; setIsAttachmentInvalid(true); setAttachmentInvalidReasonTitle('attachmentPicker.attachmentError'); setAttachmentInvalidReason('attachmentPicker.errorWhileSelectingCorruptedAttachment'); @@ -621,6 +622,13 @@ function AttachmentModal({ prompt={attachmentInvalidReason ? translate(attachmentInvalidReason) : ''} confirmText={translate('common.close')} shouldShowCancelButton={false} + onModalHide={() => { + if (!isPDFLoadError.current) { + return; + } + isPDFLoadError.current = false; + onModalHide?.(); + }} /> )} From cb2798351ebf18c8d106b1476b106fd5a1727979 Mon Sep 17 00:00:00 2001 From: dominictb Date: Mon, 23 Sep 2024 12:00:11 +0700 Subject: [PATCH 2/2] fix: lint --- src/components/AttachmentModal.tsx | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/components/AttachmentModal.tsx b/src/components/AttachmentModal.tsx index 839cd608a853..8de7f4575e75 100644 --- a/src/components/AttachmentModal.tsx +++ b/src/components/AttachmentModal.tsx @@ -2,7 +2,7 @@ import {Str} from 'expensify-common'; import React, {memo, useCallback, useEffect, useMemo, useRef, useState} from 'react'; import {Animated, Keyboard, View} from 'react-native'; import {GestureHandlerRootView} from 'react-native-gesture-handler'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; import {useSharedValue} from 'react-native-reanimated'; import type {ValueOf} from 'type-fest'; @@ -49,11 +49,6 @@ import SafeAreaConsumer from './SafeAreaConsumer'; * to display a full size image or PDF modally with optional confirmation button. */ -type AttachmentModalOnyxProps = { - /** The transaction associated with the receipt attachment, if any */ - transaction: OnyxEntry; -}; - type ImagePickerResponse = { height?: number; name: string; @@ -70,7 +65,7 @@ type ChildrenProps = { show: () => void; }; -type AttachmentModalProps = AttachmentModalOnyxProps & { +type AttachmentModalProps = { /** Optional source (URL, SVG function) for the image shown. If not passed in via props must be specified when modal is opened. */ source?: AvatarSource; @@ -154,7 +149,6 @@ function AttachmentModal({ isReceiptAttachment = false, isWorkspaceAvatar = false, maybeIcon = false, - transaction, headerTitle, children, fallbackSource, @@ -185,6 +179,9 @@ function AttachmentModal({ const nope = useSharedValue(false); const isOverlayModalVisible = (isReceiptAttachment && isDeleteReceiptConfirmModalVisible) || (!isReceiptAttachment && isAttachmentInvalid); const iouType = useMemo(() => (isTrackExpenseAction ? CONST.IOU.TYPE.TRACK : CONST.IOU.TYPE.SUBMIT), [isTrackExpenseAction]); + const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '-1', report?.parentReportActionID ?? '-1'); + const transactionID = ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction)?.IOUTransactionID ?? '-1' : '-1'; + const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`); const [file, setFile] = useState( originalFileName @@ -642,14 +639,6 @@ function AttachmentModal({ AttachmentModal.displayName = 'AttachmentModal'; -export default withOnyx({ - transaction: { - key: ({report}) => { - const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '-1', report?.parentReportActionID ?? '-1'); - const transactionID = ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction)?.IOUTransactionID ?? '-1' : '-1'; - return `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`; - }, - }, -})(memo(AttachmentModal)); +export default memo(AttachmentModal); export type {Attachment, FileObject, ImagePickerResponse};