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: keyboard overlaps pdf error modal #49328

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Changes from all commits
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
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};
Loading