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 logic get document from native #35164

Merged
merged 8 commits into from
Feb 24, 2024
Merged
Changes from 7 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
27 changes: 19 additions & 8 deletions src/components/AttachmentPicker/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,22 @@ const getImagePickerOptions = (type) => {
};

/**
* See https://github.com/rnmods/react-native-document-picker#options for DocumentPicker configuration options
* Return documentPickerOptions based on the type
* @param {String} type
* @returns {Object}
*/
const documentPickerOptions = {
type: [RNDocumentPicker.types.allFiles],
copyTo: 'cachesDirectory',

const getDocumentPickerOptions = (type) => {
if (type === CONST.ATTACHMENT_PICKER_TYPE.IMAGE) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@dukenv0307 We only return image if type is IMAGE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DylanDylann i just updated code, please check again

return {
type: [RNDocumentPicker.types.images],
copyTo: 'cachesDirectory',
};
}
return {
type: [RNDocumentPicker.types.allFiles],
copyTo: 'cachesDirectory',
};
};

/**
Expand Down Expand Up @@ -158,15 +169,15 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) {
*/
const showDocumentPicker = useCallback(
() =>
RNDocumentPicker.pick(documentPickerOptions).catch((error) => {
RNDocumentPicker.pick(getDocumentPickerOptions(type)).catch((error) => {
if (RNDocumentPicker.isCancel(error)) {
return;
}

showGeneralAlert(error.message);
throw error;
}),
[showGeneralAlert],
[showGeneralAlert, type],
);

const menuItemData = useMemo(() => {
Expand All @@ -181,15 +192,15 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) {
textTranslationKey: 'attachmentPicker.chooseFromGallery',
pickAttachment: () => showImagePicker(launchImageLibrary),
},
type !== CONST.ATTACHMENT_PICKER_TYPE.IMAGE && {
{
icon: Expensicons.Paperclip,
textTranslationKey: 'attachmentPicker.chooseDocument',
pickAttachment: showDocumentPicker,
},
]);

return data;
}, [showDocumentPicker, showImagePicker, type, shouldHideCameraOption]);
}, [showDocumentPicker, showImagePicker, shouldHideCameraOption]);

const [focusedIndex, setFocusedIndex] = useArrowKeyFocusManager({initialFocusedIndex: -1, maxIndex: menuItemData.length - 1, isActive: isVisible});

Expand Down
Loading