Skip to content
Merged
Show file tree
Hide file tree
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
27 changes: 3 additions & 24 deletions src/components/AttachmentPicker/index.native.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'underscore';
import React, {useState, useRef, useCallback, useMemo} from 'react';
import PropTypes from 'prop-types';
import {View, Alert, Linking} from 'react-native';
import {View, Alert} from 'react-native';
import RNDocumentPicker from 'react-native-document-picker';
import RNFetchBlob from 'react-native-blob-util';
import lodashCompact from 'lodash/compact';
Expand Down Expand Up @@ -110,27 +110,6 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) {
const {translate} = useLocalize();
const {isSmallScreenWidth} = useWindowDimensions();

/**
* Inform the users when they need to grant camera access and guide them to settings
*/
const showPermissionsAlert = useCallback(() => {
Alert.alert(
translate('attachmentPicker.cameraPermissionRequired'),
translate('attachmentPicker.expensifyDoesntHaveAccessToCamera'),
[
{
text: translate('common.cancel'),
style: 'cancel',
},
{
text: translate('common.settings'),
onPress: () => Linking.openSettings(),
},
],
{cancelable: false},
);
}, [translate]);

/**
* A generic handling when we don't know the exact reason for an error
*/
Expand All @@ -155,7 +134,7 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) {
if (response.errorCode) {
switch (response.errorCode) {
case 'permission':
showPermissionsAlert();
FileUtils.showCameraPermissionsAlert();
return resolve();
default:
showGeneralAlert();
Expand All @@ -168,7 +147,7 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) {
return resolve(response.assets);
});
}),
[showGeneralAlert, showPermissionsAlert, type],
[showGeneralAlert, type],
);

/**
Expand Down
22 changes: 22 additions & 0 deletions src/libs/fileDownload/FileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,27 @@ function showPermissionErrorAlert() {
]);
}

/**
* Inform the users when they need to grant camera access and guide them to settings
*/
function showCameraPermissionsAlert() {
Alert.alert(
Localize.translateLocal('attachmentPicker.cameraPermissionRequired'),
Localize.translateLocal('attachmentPicker.expensifyDoesntHaveAccessToCamera'),
[
{
text: Localize.translateLocal('common.cancel'),
style: 'cancel',
},
{
text: Localize.translateLocal('common.settings'),
onPress: () => Linking.openSettings(),
},
],
{cancelable: false},
);
}

/**
* Generate a random file name with timestamp and file extension
* @param {String} url
Expand Down Expand Up @@ -213,6 +234,7 @@ export {
showGeneralErrorAlert,
showSuccessAlert,
showPermissionErrorAlert,
showCameraPermissionsAlert,
splitExtensionFromFileName,
getAttachmentName,
getFileType,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/iou/ReceiptSelector/index.native.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ActivityIndicator, Alert, AppState, Linking, Text, View} from 'react-native';
import {ActivityIndicator, Alert, AppState, Text, View} from 'react-native';
import React, {useCallback, useEffect, useRef, useState} from 'react';
import {useCameraDevices} from 'react-native-vision-camera';
import lodashGet from 'lodash/get';
Expand Down Expand Up @@ -110,7 +110,7 @@ function ReceiptSelector({route, report, iou, transactionID, isInTabNavigator})
setCameraPermissionStatus(status);

if (status === RESULTS.BLOCKED) {
showPermissionsAlert();
FileUtils.showCameraPermissionsAlert();
}
})
.catch(() => {
Expand Down