Skip to content

Commit

Permalink
Merge pull request #49328 from dominictb/fix/48263
Browse files Browse the repository at this point in the history
fix: keyboard overlaps pdf error modal
  • Loading branch information
srikarparsi authored Sep 23, 2024
2 parents f8add4e + cb27983 commit f4a225d
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/components/AttachmentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<OnyxTypes.Transaction>;
};

type ImagePickerResponse = {
height?: number;
name: string;
Expand All @@ -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;

Expand Down Expand Up @@ -154,7 +149,6 @@ function AttachmentModal({
isReceiptAttachment = false,
isWorkspaceAvatar = false,
maybeIcon = false,
transaction,
headerTitle,
children,
fallbackSource,
Expand Down Expand Up @@ -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<FileObject | undefined>(
originalFileName
Expand Down Expand Up @@ -494,10 +491,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');
Expand Down Expand Up @@ -621,6 +619,13 @@ function AttachmentModal({
prompt={attachmentInvalidReason ? translate(attachmentInvalidReason) : ''}
confirmText={translate('common.close')}
shouldShowCancelButton={false}
onModalHide={() => {
if (!isPDFLoadError.current) {
return;
}
isPDFLoadError.current = false;
onModalHide?.();
}}
/>
)}

Expand All @@ -634,14 +639,6 @@ function AttachmentModal({

AttachmentModal.displayName = 'AttachmentModal';

export default withOnyx<AttachmentModalProps, AttachmentModalOnyxProps>({
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};

0 comments on commit f4a225d

Please sign in to comment.