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: Android web is giving option to record audio and video #47028

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
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
24 changes: 22 additions & 2 deletions src/components/AttachmentPicker/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {useRef} from 'react';
import type {ValueOf} from 'type-fest';
import Visibility from '@libs/Visibility';
import CONST from '@src/CONST';
import type AttachmentPickerProps from './types';
Expand All @@ -14,14 +15,33 @@ function getAcceptableFileTypes(type: string): string | undefined {
return 'image/*';
}

function getAcceptableFileTypesFromAList(fileTypes: Array<ValueOf<typeof CONST.API_ATTACHMENT_VALIDATIONS.ALLOWED_RECEIPT_EXTENSIONS>>): string {
const acceptValue = fileTypes
.map((type) => {
switch (type) {
case 'msword':
return 'application/msword';
case 'text':
return 'text/plain';
case 'message':
return 'message/rfc822';
default:
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
return `.${type}`;
}
})
.join(',');
return acceptValue;
}

/**
* This component renders a function as a child and
* returns a "show attachment picker" method that takes
* a callback. This is the web/mWeb/desktop version since
* on a Browser we must append a hidden input to the DOM
* and listen to onChange event.
*/
function AttachmentPicker({children, type = CONST.ATTACHMENT_PICKER_TYPE.FILE}: AttachmentPickerProps): React.JSX.Element {
function AttachmentPicker({children, type = CONST.ATTACHMENT_PICKER_TYPE.FILE, acceptedFileTypes}: AttachmentPickerProps): React.JSX.Element {
const fileInput = useRef<HTMLInputElement>(null);
const onPicked = useRef<(file: File) => void>(() => {});
const onCanceled = useRef<() => void>(() => {});
Expand Down Expand Up @@ -75,7 +95,7 @@ function AttachmentPicker({children, type = CONST.ATTACHMENT_PICKER_TYPE.FILE}:
{once: true},
);
}}
accept={getAcceptableFileTypes(type)}
accept={acceptedFileTypes ? getAcceptableFileTypesFromAList(acceptedFileTypes) : getAcceptableFileTypes(type)}
/>
{children({
openPicker: ({onPicked: newOnPicked, onCanceled: newOnCanceled = () => {}}) => {
Expand Down
2 changes: 2 additions & 0 deletions src/components/AttachmentPicker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type AttachmentPickerProps = {

/** The types of files that can be selected with this picker. */
type?: ValueOf<typeof CONST.ATTACHMENT_PICKER_TYPE>;

acceptedFileTypes?: Array<ValueOf<typeof CONST.API_ATTACHMENT_VALIDATIONS.ALLOWED_RECEIPT_EXTENSIONS>>;
};

export default AttachmentPickerProps;
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestStepScan/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ function IOURequestStepScan({
</View>

<View style={[styles.flexRow, styles.justifyContentAround, styles.alignItemsCenter, styles.pv3]}>
<AttachmentPicker>
<AttachmentPicker acceptedFileTypes={['jpg', 'jpeg', 'gif', 'png', 'pdf', 'htm', 'html', 'text', 'rtf', 'doc', 'tif', 'tiff', 'msword', 'zip', 'xml', 'message']}>
daledah marked this conversation as resolved.
Show resolved Hide resolved
{({openPicker}) => (
<PressableWithFeedback
accessibilityLabel={translate('receipt.chooseFile')}
Expand Down
Loading