Skip to content

Commit

Permalink
Migrate to expo-document-picker
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolmello committed Jun 5, 2024
1 parent 92f784d commit 6ebdf61
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 45 deletions.
45 changes: 22 additions & 23 deletions app/containers/MessageComposer/hooks/useChooseMedia.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Alert } from 'react-native';
import DocumentPicker from 'react-native-document-picker';
import * as DocumentPicker from 'expo-document-picker';

import { IMAGE_PICKER_CONFIG, LIBRARY_PICKER_CONFIG, VIDEO_PICKER_CONFIG } from '../constants';
import { forceJpgExtension } from '../helpers';
Expand Down Expand Up @@ -89,29 +89,28 @@ export const useChooseMedia = ({

const chooseFile = async () => {
try {
const res = await DocumentPicker.pickSingle({
type: [DocumentPicker.types.allFiles]
});
const file = {
filename: res.name,
size: res.size,
mime: res.type,
path: res.uri
} as any;
const canUploadResult = canUploadFile({
file,
allowList,
maxFileSize,
permissionToUploadFile: permissionToUpload
});
if (canUploadResult.success) {
return openShareView([file]);
}
handleError(canUploadResult.error);
} catch (e: any) {
if (!DocumentPicker.isCancel(e)) {
log(e);
const res = await DocumentPicker.getDocumentAsync({ copyToCacheDirectory: false });
if (!res.canceled) {
const [asset] = res.assets;
const file = {
filename: asset.name,
size: asset.size,
mime: asset.mimeType,
path: asset.uri
} as any;
const canUploadResult = canUploadFile({
file,
allowList,
maxFileSize,
permissionToUploadFile: permissionToUpload
});
if (canUploadResult.success) {
return openShareView([file]);
}
handleError(canUploadResult.error);
}
} catch (e) {
log(e);
}
};

Expand Down
10 changes: 5 additions & 5 deletions app/lib/methods/helpers/sslPinning.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Alert, NativeModules, Platform } from 'react-native';
import DocumentPicker from 'react-native-document-picker';
import * as DocumentPicker from 'expo-document-picker';
import * as FileSystem from 'expo-file-system';

import UserPreferences from '../userPreferences';
Expand Down Expand Up @@ -29,13 +29,13 @@ const RCSSLPinning = Platform.select({
pickCertificate: () =>
new Promise(async (resolve, reject) => {
try {
const res = await DocumentPicker.pickSingle({
type: ['com.rsa.pkcs-12']
const res = await DocumentPicker.getDocumentAsync({
type: 'application/x-pkcs12'
});
const { uri, name } = res;
if (!name) {
if (res.canceled) {
return reject();
}
const { uri, name } = res.assets[0];
Alert.prompt(
I18n.t('Certificate_password'),
I18n.t('Whats_the_password_for_your_certificate'),
Expand Down
12 changes: 6 additions & 6 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ PODS:
- ExpoModulesCore
- ZXingObjC/OneD
- ZXingObjC/PDF417
- ExpoDocumentPicker (11.10.1):
- ExpoModulesCore
- ExpoFileSystem (16.0.8):
- ExpoModulesCore
- ExpoHaptics (12.8.1):
Expand Down Expand Up @@ -1038,8 +1040,6 @@ PODS:
- React-Core
- react-native-cookies (6.2.1):
- React-Core
- react-native-document-picker (8.1.2):
- React-Core
- react-native-mmkv-storage (0.9.1):
- MMKV (= 1.2.13)
- React-Core
Expand Down Expand Up @@ -1330,6 +1330,7 @@ DEPENDENCIES:
- Expo (from `../node_modules/expo`)
- ExpoAppleAuthentication (from `../node_modules/expo-apple-authentication/ios`)
- ExpoCamera (from `../node_modules/expo-camera/ios`)
- ExpoDocumentPicker (from `../node_modules/expo-document-picker/ios`)
- ExpoFileSystem (from `../node_modules/expo-file-system/ios`)
- ExpoHaptics (from `../node_modules/expo-haptics/ios`)
- ExpoKeepAwake (from `../node_modules/expo-keep-awake/ios`)
Expand Down Expand Up @@ -1368,7 +1369,6 @@ DEPENDENCIES:
- react-native-background-timer (from `../node_modules/react-native-background-timer`)
- "react-native-cameraroll (from `../node_modules/@react-native-camera-roll/camera-roll`)"
- "react-native-cookies (from `../node_modules/@react-native-cookies/cookies`)"
- react-native-document-picker (from `../node_modules/react-native-document-picker`)
- react-native-mmkv-storage (from `../node_modules/react-native-mmkv-storage`)
- "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)"
- react-native-notifications (from `../node_modules/react-native-notifications`)
Expand Down Expand Up @@ -1472,6 +1472,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/expo-apple-authentication/ios"
ExpoCamera:
:path: "../node_modules/expo-camera/ios"
ExpoDocumentPicker:
:path: "../node_modules/expo-document-picker/ios"
ExpoFileSystem:
:path: "../node_modules/expo-file-system/ios"
ExpoHaptics:
Expand Down Expand Up @@ -1543,8 +1545,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/@react-native-camera-roll/camera-roll"
react-native-cookies:
:path: "../node_modules/@react-native-cookies/cookies"
react-native-document-picker:
:path: "../node_modules/react-native-document-picker"
react-native-mmkv-storage:
:path: "../node_modules/react-native-mmkv-storage"
react-native-netinfo:
Expand Down Expand Up @@ -1667,6 +1667,7 @@ SPEC CHECKSUMS:
Expo: e01a77c6fa4bc80a6d1bb949cda1d12d21044abd
ExpoAppleAuthentication: 4fc9972356977f009911f2f3a5f56319c2a5b11b
ExpoCamera: 53f5ef81bab088b2edcf94d05e4da3bc84f46383
ExpoDocumentPicker: 70254802886e29a45d4ad25486e64b6fc9c8f0cc
ExpoFileSystem: eecaf6796aed0f4dd20042dc2ca2cac6c4bc1185
ExpoHaptics: 28a771b630353cd6e8dcf1b1e3e693e38ad7c3c3
ExpoKeepAwake: 0f5cad99603a3268e50af9a6eb8b76d0d9ac956c
Expand Down Expand Up @@ -1723,7 +1724,6 @@ SPEC CHECKSUMS:
react-native-background-timer: 17ea5e06803401a379ebf1f20505b793ac44d0fe
react-native-cameraroll: 4593ffad9e619781aed27dda64739387d55ed402
react-native-cookies: f54fcded06bb0cda05c11d86788020b43528a26c
react-native-document-picker: f5ec1a712ca2a975c233117f044817bb8393cad4
react-native-mmkv-storage: cfb6854594cfdc5f7383a9e464bb025417d1721c
react-native-netinfo: bdb108d340cdb41875c9ced535977cac6d2ff321
react-native-notifications: 4601a5a8db4ced6ae7cfc43b44d35fe437ac50c4
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"expo-apple-authentication": "^6.3.0",
"expo-av": "^13.10.5",
"expo-camera": "^14.1.1",
"expo-document-picker": "11.10.1",
"expo-file-system": "^16.0.8",
"expo-haptics": "^12.8.1",
"expo-keep-awake": "^12.8.2",
Expand All @@ -91,7 +92,6 @@
"react-native-config-reader": "4.1.1",
"react-native-console-time-polyfill": "1.2.3",
"react-native-device-info": "10.3.0",
"react-native-document-picker": "8.1.2",
"react-native-easy-grid": "0.2.2",
"react-native-easy-toast": "2.3.0",
"react-native-fast-image": "RocketChat/react-native-fast-image.git#bump-version",
Expand Down
43 changes: 33 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7688,6 +7688,11 @@ expo-constants@~15.4.0:
dependencies:
"@expo/config" "~8.5.0"

[email protected]:
version "11.10.1"
resolved "https://registry.yarnpkg.com/expo-document-picker/-/expo-document-picker-11.10.1.tgz#03394d77842a2fd7cb0a784a60098ee1ddd1012e"
integrity sha512-A1MiLfyXQ+KxanRO5lYxYQy3ryV+25JHe5Ai/BLV+FJU0QXByUF+Y/dn35WVPx5gpdZXC8UJ4ejg5SKSoeconw==

expo-file-system@^16.0.8, expo-file-system@~16.0.0, expo-file-system@~16.0.8:
version "16.0.8"
resolved "https://registry.yarnpkg.com/expo-file-system/-/expo-file-system-16.0.8.tgz#13c79a8e06e42a8e76e9297df6920597a011d989"
Expand Down Expand Up @@ -11959,13 +11964,6 @@ [email protected]:
resolved "https://registry.yarnpkg.com/react-native-device-info/-/react-native-device-info-10.3.0.tgz#6bab64d84d3415dd00cc446c73ec5e2e61fddbe7"
integrity sha512-/ziZN1sA1REbJTv5mQZ4tXggcTvSbct+u5kCaze8BmN//lbxcTvWsU6NQd4IihLt89VkbX+14IGc9sVApSxd/w==

[email protected]:
version "8.1.2"
resolved "https://registry.yarnpkg.com/react-native-document-picker/-/react-native-document-picker-8.1.2.tgz#503cce26086020c833f08a405fe2da28f735ed08"
integrity sha512-R126YsjTXBuvigRRExyAQ+yn1UGV4dGcMI9x4UAY8TBTSOt6nOQcWS/AQcbzjk9MnN8ISDGqNq9GmN51Q1aHjA==
dependencies:
invariant "^2.2.4"

[email protected]:
version "3.4.8"
resolved "https://registry.yarnpkg.com/react-native-dotenv/-/react-native-dotenv-3.4.8.tgz#42284070a9994076cd700805c2dd28051c9e1432"
Expand Down Expand Up @@ -13383,7 +13381,16 @@ string-natural-compare@^3.0.1:
resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4"
integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw==

"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -13493,7 +13500,7 @@ stringify-object@^3.3.0:
is-obj "^1.0.1"
is-regexp "^1.0.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand All @@ -13507,6 +13514,13 @@ strip-ansi@^5.0.0, strip-ansi@^5.2.0:
dependencies:
ansi-regex "^4.1.0"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^7.0.1:
version "7.1.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
Expand Down Expand Up @@ -14693,7 +14707,7 @@ wordwrapjs@^4.0.0:
reduce-flatten "^2.0.0"
typical "^5.2.0"

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -14711,6 +14725,15 @@ wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down

0 comments on commit 6ebdf61

Please sign in to comment.