@sendbird/uikit-react-native 3.0.3 → 3.0.4-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,6 @@ var _uikitUtils = require("@sendbird/uikit-utils");
8
8
  var _SBUError = _interopRequireDefault(require("../libs/SBUError"));
9
9
  var _expoBackwardUtils = _interopRequireDefault(require("../utils/expoBackwardUtils"));
10
10
  var _expoPermissionGranted = _interopRequireDefault(require("../utils/expoPermissionGranted"));
11
- var _normalizeFile = _interopRequireDefault(require("../utils/normalizeFile"));
12
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
12
  const createExpoFileService = _ref => {
14
13
  let {
@@ -58,9 +57,9 @@ const createExpoFileService = _ref => {
58
57
  }
59
58
  })()
60
59
  });
61
- if (_expoBackwardUtils.default.toCanceled(response)) return null;
62
- const filePickerRes = await _expoBackwardUtils.default.toFilePickerResponses(response, fsModule);
63
- return filePickerRes[0];
60
+ if (_expoBackwardUtils.default.imagePicker.isCanceled(response)) return null;
61
+ const [file] = await _expoBackwardUtils.default.imagePicker.toFilePickerResponses(response, fsModule);
62
+ return file;
64
63
  }
65
64
  async openMediaLibrary(options) {
66
65
  const hasPermission = await this.hasMediaLibraryPermission('read');
@@ -88,27 +87,17 @@ const createExpoFileService = _ref => {
88
87
  }
89
88
  })()
90
89
  });
91
- if (_expoBackwardUtils.default.toCanceled(response)) return null;
92
- return _expoBackwardUtils.default.toFilePickerResponses(response, fsModule);
90
+ if (_expoBackwardUtils.default.imagePicker.isCanceled(response)) return null;
91
+ return _expoBackwardUtils.default.imagePicker.toFilePickerResponses(response, fsModule);
93
92
  }
94
93
  async openDocument(options) {
95
94
  try {
96
95
  const response = await documentPickerModule.getDocumentAsync({
97
96
  type: '*/*'
98
97
  });
99
- if (response.type === 'cancel') return null;
100
- const {
101
- mimeType,
102
- uri,
103
- size,
104
- name
105
- } = response;
106
- return (0, _normalizeFile.default)({
107
- uri,
108
- size,
109
- name,
110
- type: mimeType
111
- });
98
+ if (_expoBackwardUtils.default.documentPicker.isCanceled(response)) return null;
99
+ const [file] = await _expoBackwardUtils.default.documentPicker.toFilePickerResponses(response);
100
+ return file;
112
101
  } catch (e) {
113
102
  var _options$onOpenFailur3;
114
103
  options === null || options === void 0 ? void 0 : (_options$onOpenFailur3 = options.onOpenFailure) === null || _options$onOpenFailur3 === void 0 ? void 0 : _options$onOpenFailur3.call(options, _SBUError.default.UNKNOWN, e);
@@ -1 +1 @@
1
- {"version":3,"names":["_uikitUtils","require","_SBUError","_interopRequireDefault","_expoBackwardUtils","_expoPermissionGranted","_normalizeFile","obj","__esModule","default","createExpoFileService","_ref","imagePickerModule","documentPickerModule","mediaLibraryModule","fsModule","ExpoFileServiceInterface","hasCameraPermission","res","getCameraPermissionsAsync","expoPermissionGranted","requestCameraPermission","requestCameraPermissionsAsync","hasMediaLibraryPermission","type","perms","getPermissionsAsync","requestMediaLibraryPermission","requestPermissionsAsync","openCamera","options","hasPermission","granted","_options$onOpenFailur","onOpenFailure","call","SBUError","PERMISSIONS_DENIED","response","launchCameraAsync","mediaTypes","mediaType","MediaTypeOptions","Images","Videos","All","expoBackwardUtils","toCanceled","filePickerRes","toFilePickerResponses","openMediaLibrary","_options$onOpenFailur2","selectionLimit","launchImageLibraryAsync","openDocument","getDocumentAsync","mimeType","uri","size","name","normalizeFile","e","_options$onOpenFailur3","UNKNOWN","save","Error","basePath","documentDirectory","cacheDirectory","downloadPath","fileName","downloadAsync","fileUrl","getFileType","fileType","match","saveToLibraryAsync","_default","exports"],"sources":["createFileService.expo.ts"],"sourcesContent":["import type * as ExpoDocumentPicker from 'expo-document-picker';\nimport type * as ExpoFs from 'expo-file-system';\nimport type * as ExpoImagePicker from 'expo-image-picker';\nimport type * as ExpoMediaLibrary from 'expo-media-library';\n\nimport { getFileType } from '@sendbird/uikit-utils';\n\nimport SBUError from '../libs/SBUError';\nimport expoBackwardUtils from '../utils/expoBackwardUtils';\nimport type { ExpoMediaLibraryPermissionResponse, ExpoPermissionResponse } from '../utils/expoPermissionGranted';\nimport expoPermissionGranted from '../utils/expoPermissionGranted';\nimport normalizeFile from '../utils/normalizeFile';\nimport type {\n FilePickerResponse,\n FileServiceInterface,\n OpenCameraOptions,\n OpenDocumentOptions,\n OpenMediaLibraryOptions,\n SaveOptions,\n} from './types';\n\nconst createExpoFileService = ({\n imagePickerModule,\n documentPickerModule,\n mediaLibraryModule,\n fsModule,\n}: {\n imagePickerModule: typeof ExpoImagePicker;\n documentPickerModule: typeof ExpoDocumentPicker;\n mediaLibraryModule: typeof ExpoMediaLibrary;\n fsModule: typeof ExpoFs;\n}): FileServiceInterface => {\n class ExpoFileServiceInterface implements FileServiceInterface {\n async hasCameraPermission(): Promise<boolean> {\n const res = (await imagePickerModule.getCameraPermissionsAsync()) as ExpoPermissionResponse;\n return expoPermissionGranted([res]);\n }\n async requestCameraPermission(): Promise<boolean> {\n const res = (await imagePickerModule.requestCameraPermissionsAsync()) as ExpoPermissionResponse;\n return expoPermissionGranted([res]);\n }\n async hasMediaLibraryPermission(type: 'write' | 'read'): Promise<boolean> {\n const perms = (await mediaLibraryModule.getPermissionsAsync(\n type === 'write',\n )) as ExpoMediaLibraryPermissionResponse;\n return expoPermissionGranted([perms]);\n }\n async requestMediaLibraryPermission(type: 'write' | 'read'): Promise<boolean> {\n const perms = (await mediaLibraryModule.requestPermissionsAsync(\n type === 'write',\n )) as ExpoMediaLibraryPermissionResponse;\n return expoPermissionGranted([perms]);\n }\n\n async openCamera(options?: OpenCameraOptions): Promise<FilePickerResponse> {\n const hasPermission = await this.hasCameraPermission();\n if (!hasPermission) {\n const granted = await this.requestCameraPermission();\n if (!granted) {\n options?.onOpenFailure?.(SBUError.PERMISSIONS_DENIED);\n return null;\n }\n }\n\n const response = await imagePickerModule.launchCameraAsync({\n mediaTypes: (() => {\n switch (options?.mediaType) {\n case 'photo':\n return imagePickerModule.MediaTypeOptions.Images;\n case 'video':\n return imagePickerModule.MediaTypeOptions.Videos;\n case 'all':\n return imagePickerModule.MediaTypeOptions.All;\n default:\n return imagePickerModule.MediaTypeOptions.Images;\n }\n })(),\n });\n\n if (expoBackwardUtils.toCanceled(response)) return null;\n\n const filePickerRes = await expoBackwardUtils.toFilePickerResponses(response, fsModule);\n return filePickerRes[0];\n }\n async openMediaLibrary(options: OpenMediaLibraryOptions) {\n const hasPermission = await this.hasMediaLibraryPermission('read');\n if (!hasPermission) {\n const granted = await this.requestMediaLibraryPermission('read');\n if (!granted) {\n options?.onOpenFailure?.(SBUError.PERMISSIONS_DENIED);\n return null;\n }\n }\n\n const selectionLimit = options?.selectionLimit || 1;\n const response = await imagePickerModule.launchImageLibraryAsync({\n selectionLimit,\n mediaTypes: (() => {\n switch (options?.mediaType) {\n case 'photo':\n return imagePickerModule.MediaTypeOptions.Images;\n case 'video':\n return imagePickerModule.MediaTypeOptions.Videos;\n case 'all':\n return imagePickerModule.MediaTypeOptions.All;\n default:\n return imagePickerModule.MediaTypeOptions.Images;\n }\n })(),\n });\n if (expoBackwardUtils.toCanceled(response)) return null;\n return expoBackwardUtils.toFilePickerResponses(response, fsModule);\n }\n\n async openDocument(options?: OpenDocumentOptions): Promise<FilePickerResponse> {\n try {\n const response = await documentPickerModule.getDocumentAsync({ type: '*/*' });\n if (response.type === 'cancel') return null;\n const { mimeType, uri, size, name } = response;\n return normalizeFile({ uri, size, name, type: mimeType });\n } catch (e) {\n options?.onOpenFailure?.(SBUError.UNKNOWN, e);\n return null;\n }\n }\n\n async save(options: SaveOptions): Promise<string> {\n const hasPermission = await this.hasMediaLibraryPermission('write');\n if (!hasPermission) {\n const granted = await this.requestMediaLibraryPermission('write');\n if (!granted) throw new Error('Permission not granted');\n }\n\n const basePath = fsModule.documentDirectory || fsModule.cacheDirectory;\n if (!basePath) throw new Error('Cannot determine directory');\n\n const downloadPath = `${basePath}/${options.fileName}`;\n\n const response = await fsModule.downloadAsync(options.fileUrl, downloadPath);\n if (getFileType(options.fileType || '').match(/video|image/)) {\n await mediaLibraryModule.saveToLibraryAsync(response.uri);\n }\n return response.uri;\n }\n }\n\n return new ExpoFileServiceInterface();\n};\n\nexport default createExpoFileService;\n"],"mappings":";;;;;;AAKA,IAAAA,WAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAD,sBAAA,CAAAF,OAAA;AAEA,IAAAI,sBAAA,GAAAF,sBAAA,CAAAF,OAAA;AACA,IAAAK,cAAA,GAAAH,sBAAA,CAAAF,OAAA;AAAmD,SAAAE,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAUnD,MAAMG,qBAAqB,GAAGC,IAAA,IAUF;EAAA,IAVG;IAC7BC,iBAAiB;IACjBC,oBAAoB;IACpBC,kBAAkB;IAClBC;EAMF,CAAC,GAAAJ,IAAA;EACC,MAAMK,wBAAwB,CAAiC;IAC7D,MAAMC,mBAAmBA,CAAA,EAAqB;MAC5C,MAAMC,GAAG,GAAI,MAAMN,iBAAiB,CAACO,yBAAyB,EAA6B;MAC3F,OAAO,IAAAC,8BAAqB,EAAC,CAACF,GAAG,CAAC,CAAC;IACrC;IACA,MAAMG,uBAAuBA,CAAA,EAAqB;MAChD,MAAMH,GAAG,GAAI,MAAMN,iBAAiB,CAACU,6BAA6B,EAA6B;MAC/F,OAAO,IAAAF,8BAAqB,EAAC,CAACF,GAAG,CAAC,CAAC;IACrC;IACA,MAAMK,yBAAyBA,CAACC,IAAsB,EAAoB;MACxE,MAAMC,KAAK,GAAI,MAAMX,kBAAkB,CAACY,mBAAmB,CACzDF,IAAI,KAAK,OAAO,CACsB;MACxC,OAAO,IAAAJ,8BAAqB,EAAC,CAACK,KAAK,CAAC,CAAC;IACvC;IACA,MAAME,6BAA6BA,CAACH,IAAsB,EAAoB;MAC5E,MAAMC,KAAK,GAAI,MAAMX,kBAAkB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;MAC5E,IAAI,IAAAI,uBAAW,EAAC3C,OAAO,CAAC4C,QAAQ,IAAI,EAAE,CAAC,CAACC,KAAK,CAAC,aAAa,CAAC,EAAE;QAC5D,MAAM7D,kBAAkB,CAAC8D,kBAAkB,CAACtC,QAAQ,CAACmB,GAAG,CAAC;MAC3D;MACA,OAAOnB,QAAQ,CAACmB,GAAG;IACrB;EACF;EAEA,OAAO,IAAIzC,wBAAwB,EAAE;AACvC,CAAC;AAAC,IAAA6D,QAAA,GAEanE,qBAAqB;AAAAoE,OAAA,CAAArE,OAAA,GAAAoE,QAAA"}
1
+ {"version":3,"names":["_uikitUtils","require","_SBUError","_interopRequireDefault","_expoBackwardUtils","_expoPermissionGranted","obj","__esModule","default","createExpoFileService","_ref","imagePickerModule","documentPickerModule","mediaLibraryModule","fsModule","ExpoFileServiceInterface","hasCameraPermission","res","getCameraPermissionsAsync","expoPermissionGranted","requestCameraPermission","requestCameraPermissionsAsync","hasMediaLibraryPermission","type","perms","getPermissionsAsync","requestMediaLibraryPermission","requestPermissionsAsync","openCamera","options","hasPermission","granted","_options$onOpenFailur","onOpenFailure","call","SBUError","PERMISSIONS_DENIED","response","launchCameraAsync","mediaTypes","mediaType","MediaTypeOptions","Images","Videos","All","expoBackwardUtils","imagePicker","isCanceled","file","toFilePickerResponses","openMediaLibrary","_options$onOpenFailur2","selectionLimit","launchImageLibraryAsync","openDocument","getDocumentAsync","documentPicker","e","_options$onOpenFailur3","UNKNOWN","save","Error","basePath","documentDirectory","cacheDirectory","downloadPath","fileName","downloadAsync","fileUrl","getFileType","fileType","match","saveToLibraryAsync","uri","_default","exports"],"sources":["createFileService.expo.ts"],"sourcesContent":["import type * as ExpoDocumentPicker from 'expo-document-picker';\nimport type * as ExpoFs from 'expo-file-system';\nimport type * as ExpoImagePicker from 'expo-image-picker';\nimport type * as ExpoMediaLibrary from 'expo-media-library';\n\nimport { getFileType } from '@sendbird/uikit-utils';\n\nimport SBUError from '../libs/SBUError';\nimport expoBackwardUtils from '../utils/expoBackwardUtils';\nimport type { ExpoMediaLibraryPermissionResponse, ExpoPermissionResponse } from '../utils/expoPermissionGranted';\nimport expoPermissionGranted from '../utils/expoPermissionGranted';\nimport type {\n FilePickerResponse,\n FileServiceInterface,\n OpenCameraOptions,\n OpenDocumentOptions,\n OpenMediaLibraryOptions,\n SaveOptions,\n} from './types';\n\nconst createExpoFileService = ({\n imagePickerModule,\n documentPickerModule,\n mediaLibraryModule,\n fsModule,\n}: {\n imagePickerModule: typeof ExpoImagePicker;\n documentPickerModule: typeof ExpoDocumentPicker;\n mediaLibraryModule: typeof ExpoMediaLibrary;\n fsModule: typeof ExpoFs;\n}): FileServiceInterface => {\n class ExpoFileServiceInterface implements FileServiceInterface {\n async hasCameraPermission(): Promise<boolean> {\n const res = (await imagePickerModule.getCameraPermissionsAsync()) as ExpoPermissionResponse;\n return expoPermissionGranted([res]);\n }\n async requestCameraPermission(): Promise<boolean> {\n const res = (await imagePickerModule.requestCameraPermissionsAsync()) as ExpoPermissionResponse;\n return expoPermissionGranted([res]);\n }\n async hasMediaLibraryPermission(type: 'write' | 'read'): Promise<boolean> {\n const perms = (await mediaLibraryModule.getPermissionsAsync(\n type === 'write',\n )) as ExpoMediaLibraryPermissionResponse;\n return expoPermissionGranted([perms]);\n }\n async requestMediaLibraryPermission(type: 'write' | 'read'): Promise<boolean> {\n const perms = (await mediaLibraryModule.requestPermissionsAsync(\n type === 'write',\n )) as ExpoMediaLibraryPermissionResponse;\n return expoPermissionGranted([perms]);\n }\n\n async openCamera(options?: OpenCameraOptions): Promise<FilePickerResponse> {\n const hasPermission = await this.hasCameraPermission();\n if (!hasPermission) {\n const granted = await this.requestCameraPermission();\n if (!granted) {\n options?.onOpenFailure?.(SBUError.PERMISSIONS_DENIED);\n return null;\n }\n }\n\n const response = await imagePickerModule.launchCameraAsync({\n mediaTypes: (() => {\n switch (options?.mediaType) {\n case 'photo':\n return imagePickerModule.MediaTypeOptions.Images;\n case 'video':\n return imagePickerModule.MediaTypeOptions.Videos;\n case 'all':\n return imagePickerModule.MediaTypeOptions.All;\n default:\n return imagePickerModule.MediaTypeOptions.Images;\n }\n })(),\n });\n\n if (expoBackwardUtils.imagePicker.isCanceled(response)) return null;\n\n const [file] = await expoBackwardUtils.imagePicker.toFilePickerResponses(response, fsModule);\n return file;\n }\n async openMediaLibrary(options: OpenMediaLibraryOptions) {\n const hasPermission = await this.hasMediaLibraryPermission('read');\n if (!hasPermission) {\n const granted = await this.requestMediaLibraryPermission('read');\n if (!granted) {\n options?.onOpenFailure?.(SBUError.PERMISSIONS_DENIED);\n return null;\n }\n }\n\n const selectionLimit = options?.selectionLimit || 1;\n const response = await imagePickerModule.launchImageLibraryAsync({\n selectionLimit,\n mediaTypes: (() => {\n switch (options?.mediaType) {\n case 'photo':\n return imagePickerModule.MediaTypeOptions.Images;\n case 'video':\n return imagePickerModule.MediaTypeOptions.Videos;\n case 'all':\n return imagePickerModule.MediaTypeOptions.All;\n default:\n return imagePickerModule.MediaTypeOptions.Images;\n }\n })(),\n });\n if (expoBackwardUtils.imagePicker.isCanceled(response)) return null;\n return expoBackwardUtils.imagePicker.toFilePickerResponses(response, fsModule);\n }\n\n async openDocument(options?: OpenDocumentOptions): Promise<FilePickerResponse> {\n try {\n const response = await documentPickerModule.getDocumentAsync({ type: '*/*' });\n if (expoBackwardUtils.documentPicker.isCanceled(response)) return null;\n\n const [file] = await expoBackwardUtils.documentPicker.toFilePickerResponses(response);\n return file;\n } catch (e) {\n options?.onOpenFailure?.(SBUError.UNKNOWN, e);\n return null;\n }\n }\n\n async save(options: SaveOptions): Promise<string> {\n const hasPermission = await this.hasMediaLibraryPermission('write');\n if (!hasPermission) {\n const granted = await this.requestMediaLibraryPermission('write');\n if (!granted) throw new Error('Permission not granted');\n }\n\n const basePath = fsModule.documentDirectory || fsModule.cacheDirectory;\n if (!basePath) throw new Error('Cannot determine directory');\n\n const downloadPath = `${basePath}/${options.fileName}`;\n\n const response = await fsModule.downloadAsync(options.fileUrl, downloadPath);\n if (getFileType(options.fileType || '').match(/video|image/)) {\n await mediaLibraryModule.saveToLibraryAsync(response.uri);\n }\n return response.uri;\n }\n }\n\n return new ExpoFileServiceInterface();\n};\n\nexport default createExpoFileService;\n"],"mappings":";;;;;;AAKA,IAAAA,WAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAD,sBAAA,CAAAF,OAAA;AAEA,IAAAI,sBAAA,GAAAF,sBAAA,CAAAF,OAAA;AAAmE,SAAAE,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAUnE,MAAMG,qBAAqB,GAAGC,IAAA,IAUF;EAAA,IAVG;IAC7BC,iBAAiB;IACjBC,oBAAoB;IACpBC,kBAAkB;IAClBC;EAMF,CAAC,GAAAJ,IAAA;EACC,MAAMK,wBAAwB,CAAiC;IAC7D,MAAMC,mBAAmBA,CAAA,EAAqB;MAC5C,MAAMC,GAAG,GAAI,MAAMN,iBAAiB,CAACO,yBAAyB,EAA6B;MAC3F,OAAO,IAAAC,8BAAqB,EAAC,CAACF,GAAG,CAAC,CAAC;IACrC;IACA,MAAMG,uBAAuBA,CAAA,EAAqB;MAChD,MAAMH,GAAG,GAAI,MAAMN,iBAAiB,CAACU,6BAA6B,EAA6B;MAC/F,OAAO,IAAAF,8BAAqB,EAAC,CAACF,GAAG,CAAC,CAAC;IACrC;IACA,MAAMK,yBAAyBA,CAACC,IAAsB,EAAoB;MACxE,MAAMC,KAAK,GAAI,MAAMX,kBAAkB,CAACY,mBAAmB,CACzDF,IAAI,KAAK,OAAO,CACsB;MACxC,OAAO,IAAAJ,8BAAqB,EAAC,CAACK,KAAK,CAAC,CAAC;IACvC;IACA,MAAME,6BAA6BA,CAACH,IAAsB,EAAoB;MAC5E,MAAMC,KAAK,GAAI,MAAMX,kBAAkB,CAACc,uBAAuB,CAC7D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C,QAAQ,IAAI,EAAE,CAAC,CAACC,KAAK,CAAC,aAAa,CAAC,EAAE;QAC5D,MAAM1D,kBAAkB,CAAC2D,kBAAkB,CAACnC,QAAQ,CAACoC,GAAG,CAAC;MAC3D;MACA,OAAOpC,QAAQ,CAACoC,GAAG;IACrB;EACF;EAEA,OAAO,IAAI1D,wBAAwB,EAAE;AACvC,CAAC;AAAC,IAAA2D,QAAA,GAEajE,qBAAqB;AAAAkE,OAAA,CAAAnE,OAAA,GAAAkE,QAAA"}
@@ -7,44 +7,89 @@ exports.default = void 0;
7
7
  var _normalizeFile = _interopRequireDefault(require("./normalizeFile"));
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
9
  const expoBackwardUtils = {
10
- toCanceled(result) {
11
- // @ts-expect-error backward compatibility
12
- return result.canceled ?? result.cancelled;
13
- },
14
- toFileSize(info) {
15
- if ('size' in info) {
16
- return info.size;
17
- } else {
18
- return 0;
10
+ imagePicker: {
11
+ isCanceled(result) {
12
+ // @ts-expect-error backward compatibility
13
+ return result.canceled ?? result.cancelled;
14
+ },
15
+ async toFilePickerResponses(result, fsModule) {
16
+ if (result.assets) {
17
+ const assets = result.assets || [];
18
+ const promises = assets.map(_ref => {
19
+ let {
20
+ fileName: name,
21
+ fileSize: size,
22
+ type,
23
+ uri
24
+ } = _ref;
25
+ return (0, _normalizeFile.default)({
26
+ uri,
27
+ size,
28
+ name,
29
+ type
30
+ });
31
+ });
32
+ return Promise.all(promises);
33
+ } else if ('uri' in result && typeof result.uri === 'string') {
34
+ const fileInfo = await fsModule.getInfoAsync(result.uri);
35
+ const response = await (0, _normalizeFile.default)({
36
+ uri: result.uri,
37
+ size: expoBackwardUtils.toFileSize(fileInfo)
38
+ });
39
+ return [response];
40
+ } else {
41
+ return [];
42
+ }
19
43
  }
20
44
  },
21
- async toFilePickerResponses(result, fsModule) {
22
- if (result.assets) {
23
- const assets = result.assets || [];
24
- const promises = assets.map(_ref => {
25
- let {
26
- fileName: name,
27
- fileSize: size,
28
- type,
29
- uri
30
- } = _ref;
31
- return (0, _normalizeFile.default)({
45
+ documentPicker: {
46
+ isCanceled(result) {
47
+ // @ts-expect-error backward compatibility
48
+ return result.canceled ?? result.type === 'cancel';
49
+ },
50
+ async toFilePickerResponses(result) {
51
+ if (result.assets) {
52
+ const assets = result.assets || [];
53
+ const promises = assets.map(_ref2 => {
54
+ let {
55
+ name,
56
+ size,
57
+ mimeType,
58
+ uri
59
+ } = _ref2;
60
+ return (0, _normalizeFile.default)({
61
+ uri,
62
+ size,
63
+ name,
64
+ type: mimeType
65
+ });
66
+ });
67
+ return Promise.all(promises);
68
+ } else if ('uri' in result && typeof result.uri === 'string') {
69
+ // @ts-expect-error backward compatibility
70
+ const {
71
+ mimeType,
72
+ uri,
73
+ size,
74
+ name
75
+ } = result;
76
+ const response = await (0, _normalizeFile.default)({
32
77
  uri,
33
78
  size,
34
79
  name,
35
- type
80
+ type: mimeType
36
81
  });
37
- });
38
- return Promise.all(promises);
39
- } else if ('uri' in result && typeof result.uri === 'string') {
40
- const fileInfo = await fsModule.getInfoAsync(result.uri);
41
- const response = await (0, _normalizeFile.default)({
42
- uri: result.uri,
43
- size: this.toFileSize(fileInfo)
44
- });
45
- return [response];
82
+ return [response];
83
+ } else {
84
+ return [];
85
+ }
86
+ }
87
+ },
88
+ toFileSize(info) {
89
+ if ('size' in info) {
90
+ return info.size;
46
91
  } else {
47
- return [];
92
+ return 0;
48
93
  }
49
94
  }
50
95
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_normalizeFile","_interopRequireDefault","require","obj","__esModule","default","expoBackwardUtils","toCanceled","result","canceled","cancelled","toFileSize","info","size","toFilePickerResponses","fsModule","assets","promises","map","_ref","fileName","name","fileSize","type","uri","normalizeFile","Promise","all","fileInfo","getInfoAsync","response","_default","exports"],"sources":["expoBackwardUtils.ts"],"sourcesContent":["import type * as ExpoFs from 'expo-file-system';\nimport type * as ExpoImagePicker from 'expo-image-picker';\n\nimport type { FilePickerResponse } from '../platform/types';\nimport normalizeFile from './normalizeFile';\n\nconst expoBackwardUtils = {\n toCanceled(result: ExpoImagePicker.ImagePickerResult) {\n // @ts-expect-error backward compatibility\n return result.canceled ?? result.cancelled;\n },\n toFileSize(info: ExpoFs.FileInfo) {\n if ('size' in info) {\n return info.size;\n } else {\n return 0;\n }\n },\n async toFilePickerResponses(\n result: ExpoImagePicker.ImagePickerResult,\n fsModule: typeof ExpoFs,\n ): Promise<FilePickerResponse[]> {\n if (result.assets) {\n const assets = result.assets || [];\n const promises = assets.map(({ fileName: name, fileSize: size, type, uri }) =>\n normalizeFile({ uri, size, name, type }),\n );\n\n return Promise.all(promises);\n } else if ('uri' in result && typeof result.uri === 'string') {\n const fileInfo = await fsModule.getInfoAsync(result.uri);\n const response = await normalizeFile({ uri: result.uri, size: this.toFileSize(fileInfo) });\n return [response];\n } else {\n return [];\n }\n },\n};\n\nexport default expoBackwardUtils;\n"],"mappings":";;;;;;AAIA,IAAAA,cAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA4C,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE5C,MAAMG,iBAAiB,GAAG;EACxBC,UAAUA,CAACC,MAAyC,EAAE;IACpD;IACA,OAAOA,MAAM,CAACC,QAAQ,IAAID,MAAM,CAACE,SAAS;EAC5C,CAAC;EACDC,UAAUA,CAACC,IAAqB,EAAE;IAChC,IAAI,MAAM,IAAIA,IAAI,EAAE;MAClB,OAAOA,IAAI,CAACC,IAAI;IAClB,CAAC,MAAM;MACL,OAAO,CAAC;IACV;EACF,CAAC;EACD,MAAMC,qBAAqBA,CACzBN,MAAyC,EACzCO,QAAuB,EACQ;IAC/B,IAAIP,MAAM,CAACQ,MAAM,EAAE;MACjB,MAAMA,MAAM,GAAGR,MAAM,CAACQ,MAAM,IAAI,EAAE;MAClC,MAAMC,QAAQ,GAAGD,MAAM,CAACE,GAAG,CAACC,IAAA;QAAA,IAAC;UAAEC,QAAQ,EAAEC,IAAI;UAAEC,QAAQ,EAAET,IAAI;UAAEU,IAAI;UAAEC;QAAI,CAAC,GAAAL,IAAA;QAAA,OACxE,IAAAM,sBAAa,EAAC;UAAED,GAAG;UAAEX,IAAI;UAAEQ,IAAI;UAAEE;QAAK,CAAC,CAAC;MAAA,EACzC;MAED,OAAOG,OAAO,CAACC,GAAG,CAACV,QAAQ,CAAC;IAC9B,CAAC,MAAM,IAAI,KAAK,IAAIT,MAAM,IAAI,OAAOA,MAAM,CAACgB,GAAG,KAAK,QAAQ,EAAE;MAC5D,MAAMI,QAAQ,GAAG,MAAMb,QAAQ,CAACc,YAAY,CAACrB,MAAM,CAACgB,GAAG,CAAC;MACxD,MAAMM,QAAQ,GAAG,MAAM,IAAAL,sBAAa,EAAC;QAAED,GAAG,EAAEhB,MAAM,CAACgB,GAAG;QAAEX,IAAI,EAAE,IAAI,CAACF,UAAU,CAACiB,QAAQ;MAAE,CAAC,CAAC;MAC1F,OAAO,CAACE,QAAQ,CAAC;IACnB,CAAC,MAAM;MACL,OAAO,EAAE;IACX;EACF;AACF,CAAC;AAAC,IAAAC,QAAA,GAEazB,iBAAiB;AAAA0B,OAAA,CAAA3B,OAAA,GAAA0B,QAAA"}
1
+ {"version":3,"names":["_normalizeFile","_interopRequireDefault","require","obj","__esModule","default","expoBackwardUtils","imagePicker","isCanceled","result","canceled","cancelled","toFilePickerResponses","fsModule","assets","promises","map","_ref","fileName","name","fileSize","size","type","uri","normalizeFile","Promise","all","fileInfo","getInfoAsync","response","toFileSize","documentPicker","_ref2","mimeType","info","_default","exports"],"sources":["expoBackwardUtils.ts"],"sourcesContent":["import type * as ExpoDocumentPicker from 'expo-document-picker';\nimport type * as ExpoFs from 'expo-file-system';\nimport type * as ExpoImagePicker from 'expo-image-picker';\n\nimport type { FilePickerResponse } from '../platform/types';\nimport normalizeFile from './normalizeFile';\n\nconst expoBackwardUtils = {\n imagePicker: {\n isCanceled(result: ExpoImagePicker.ImagePickerResult) {\n // @ts-expect-error backward compatibility\n return result.canceled ?? result.cancelled;\n },\n async toFilePickerResponses(\n result: ExpoImagePicker.ImagePickerResult,\n fsModule: typeof ExpoFs,\n ): Promise<FilePickerResponse[]> {\n if (result.assets) {\n const assets = result.assets || [];\n const promises = assets.map(({ fileName: name, fileSize: size, type, uri }) =>\n normalizeFile({ uri, size, name, type }),\n );\n\n return Promise.all(promises);\n } else if ('uri' in result && typeof result.uri === 'string') {\n const fileInfo = await fsModule.getInfoAsync(result.uri);\n const response = await normalizeFile({ uri: result.uri, size: expoBackwardUtils.toFileSize(fileInfo) });\n return [response];\n } else {\n return [];\n }\n },\n },\n documentPicker: {\n isCanceled(result: ExpoDocumentPicker.DocumentPickerResult) {\n // @ts-expect-error backward compatibility\n return result.canceled ?? result.type === 'cancel';\n },\n async toFilePickerResponses(result: ExpoDocumentPicker.DocumentPickerResult): Promise<FilePickerResponse[]> {\n if (result.assets) {\n const assets = result.assets || [];\n const promises = assets.map(({ name, size, mimeType, uri }) =>\n normalizeFile({ uri, size, name, type: mimeType }),\n );\n\n return Promise.all(promises);\n } else if ('uri' in result && typeof result.uri === 'string') {\n // @ts-expect-error backward compatibility\n const { mimeType, uri, size, name } = result;\n const response = await normalizeFile({ uri, size, name, type: mimeType });\n\n return [response];\n } else {\n return [];\n }\n },\n },\n toFileSize(info: ExpoFs.FileInfo) {\n if ('size' in info) {\n return info.size;\n } else {\n return 0;\n }\n },\n};\n\nexport default expoBackwardUtils;\n"],"mappings":";;;;;;AAKA,IAAAA,cAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA4C,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE5C,MAAMG,iBAAiB,GAAG;EACxBC,WAAW,EAAE;IACXC,UAAUA,CAACC,MAAyC,EAAE;MACpD;MACA,OAAOA,MAAM,CA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AAE;QAClC,MAAMC,QAAQ,GAAGD,MAAM,CAACE,GAAG,CAACgB,KAAA;UAAA,IAAC;YAAEb,IAAI;YAAEE,IAAI;YAAEY,QAAQ;YAAEV;UAAI,CAAC,GAAAS,KAAA;UAAA,OACxD,IAAAR,sBAAa,EAAC;YAAED,GAAG;YAAEF,IAAI;YAAEF,IAAI;YAAEG,IAAI,EAAEW;UAAS,CAAC,CAAC;QAAA,EACnD;QAED,OAAOR,OAAO,CAACC,GAAG,CAACX,QAAQ,CAAC;MAC9B,CAAC,MAAM,IAAI,KAAK,IAAIN,MAAM,IAAI,OAAOA,MAAM,CAACc,GAAG,KAAK,QAAQ,EAAE;QAC5D;QACA,MAAM;UAAEU,QAAQ;UAAEV,GAAG;UAAEF,IAAI;UAAEF;QAAK,CAAC,GAAGV,MAAM;QAC5C,MAAMoB,QAAQ,GAAG,MAAM,IAAAL,sBAAa,EAAC;UAAED,GAAG;UAAEF,IAAI;UAAEF,IAAI;UAAEG,IAAI,EAAEW;QAAS,CAAC,CAAC;QAEzE,OAAO,CAACJ,QAAQ,CAAC;MACnB,CAAC,MAAM;QACL,OAAO,EAAE;MACX;IACF;EACF,CAAC;EACDC,UAAUA,CAACI,IAAqB,EAAE;IAChC,IAAI,MAAM,IAAIA,IAAI,EAAE;MAClB,OAAOA,IAAI,CAACb,IAAI;IAClB,CAAC,MAAM;MACL,OAAO,CAAC;IACV;EACF;AACF,CAAC;AAAC,IAAAc,QAAA,GAEa7B,iBAAiB;AAAA8B,OAAA,CAAA/B,OAAA,GAAA8B,QAAA"}
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- const VERSION = '3.0.3';
7
+ const VERSION = '3.0.4-rc.1';
8
8
  var _default = VERSION;
9
9
  exports.default = _default;
10
10
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["VERSION","_default","exports","default"],"sources":["version.ts"],"sourcesContent":["const VERSION = '3.0.3';\nexport default VERSION;\n"],"mappings":";;;;;;AAAA,MAAMA,OAAO,GAAG,OAAO;AAAC,IAAAC,QAAA,GACTD,OAAO;AAAAE,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
1
+ {"version":3,"names":["VERSION","_default","exports","default"],"sources":["version.ts"],"sourcesContent":["const VERSION = '3.0.4-rc.1';\nexport default VERSION;\n"],"mappings":";;;;;;AAAA,MAAMA,OAAO,GAAG,YAAY;AAAC,IAAAC,QAAA,GACdD,OAAO;AAAAE,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
@@ -2,7 +2,6 @@ import { getFileType } from '@sendbird/uikit-utils';
2
2
  import SBUError from '../libs/SBUError';
3
3
  import expoBackwardUtils from '../utils/expoBackwardUtils';
4
4
  import expoPermissionGranted from '../utils/expoPermissionGranted';
5
- import normalizeFile from '../utils/normalizeFile';
6
5
  const createExpoFileService = _ref => {
7
6
  let {
8
7
  imagePickerModule,
@@ -51,9 +50,9 @@ const createExpoFileService = _ref => {
51
50
  }
52
51
  })()
53
52
  });
54
- if (expoBackwardUtils.toCanceled(response)) return null;
55
- const filePickerRes = await expoBackwardUtils.toFilePickerResponses(response, fsModule);
56
- return filePickerRes[0];
53
+ if (expoBackwardUtils.imagePicker.isCanceled(response)) return null;
54
+ const [file] = await expoBackwardUtils.imagePicker.toFilePickerResponses(response, fsModule);
55
+ return file;
57
56
  }
58
57
  async openMediaLibrary(options) {
59
58
  const hasPermission = await this.hasMediaLibraryPermission('read');
@@ -81,27 +80,17 @@ const createExpoFileService = _ref => {
81
80
  }
82
81
  })()
83
82
  });
84
- if (expoBackwardUtils.toCanceled(response)) return null;
85
- return expoBackwardUtils.toFilePickerResponses(response, fsModule);
83
+ if (expoBackwardUtils.imagePicker.isCanceled(response)) return null;
84
+ return expoBackwardUtils.imagePicker.toFilePickerResponses(response, fsModule);
86
85
  }
87
86
  async openDocument(options) {
88
87
  try {
89
88
  const response = await documentPickerModule.getDocumentAsync({
90
89
  type: '*/*'
91
90
  });
92
- if (response.type === 'cancel') return null;
93
- const {
94
- mimeType,
95
- uri,
96
- size,
97
- name
98
- } = response;
99
- return normalizeFile({
100
- uri,
101
- size,
102
- name,
103
- type: mimeType
104
- });
91
+ if (expoBackwardUtils.documentPicker.isCanceled(response)) return null;
92
+ const [file] = await expoBackwardUtils.documentPicker.toFilePickerResponses(response);
93
+ return file;
105
94
  } catch (e) {
106
95
  var _options$onOpenFailur3;
107
96
  options === null || options === void 0 ? void 0 : (_options$onOpenFailur3 = options.onOpenFailure) === null || _options$onOpenFailur3 === void 0 ? void 0 : _options$onOpenFailur3.call(options, SBUError.UNKNOWN, e);
@@ -1 +1 @@
1
- {"version":3,"names":["getFileType","SBUError","expoBackwardUtils","expoPermissionGranted","normalizeFile","createExpoFileService","_ref","imagePickerModule","documentPickerModule","mediaLibraryModule","fsModule","ExpoFileServiceInterface","hasCameraPermission","res","getCameraPermissionsAsync","requestCameraPermission","requestCameraPermissionsAsync","hasMediaLibraryPermission","type","perms","getPermissionsAsync","requestMediaLibraryPermission","requestPermissionsAsync","openCamera","options","hasPermission","granted","_options$onOpenFailur","onOpenFailure","call","PERMISSIONS_DENIED","response","launchCameraAsync","mediaTypes","mediaType","MediaTypeOptions","Images","Videos","All","toCanceled","filePickerRes","toFilePickerResponses","openMediaLibrary","_options$onOpenFailur2","selectionLimit","launchImageLibraryAsync","openDocument","getDocumentAsync","mimeType","uri","size","name","e","_options$onOpenFailur3","UNKNOWN","save","Error","basePath","documentDirectory","cacheDirectory","downloadPath","fileName","downloadAsync","fileUrl","fileType","match","saveToLibraryAsync"],"sources":["createFileService.expo.ts"],"sourcesContent":["import type * as ExpoDocumentPicker from 'expo-document-picker';\nimport type * as ExpoFs from 'expo-file-system';\nimport type * as ExpoImagePicker from 'expo-image-picker';\nimport type * as ExpoMediaLibrary from 'expo-media-library';\n\nimport { getFileType } from '@sendbird/uikit-utils';\n\nimport SBUError from '../libs/SBUError';\nimport expoBackwardUtils from '../utils/expoBackwardUtils';\nimport type { ExpoMediaLibraryPermissionResponse, ExpoPermissionResponse } from '../utils/expoPermissionGranted';\nimport expoPermissionGranted from '../utils/expoPermissionGranted';\nimport normalizeFile from '../utils/normalizeFile';\nimport type {\n FilePickerResponse,\n FileServiceInterface,\n OpenCameraOptions,\n OpenDocumentOptions,\n OpenMediaLibraryOptions,\n SaveOptions,\n} from './types';\n\nconst createExpoFileService = ({\n imagePickerModule,\n documentPickerModule,\n mediaLibraryModule,\n fsModule,\n}: {\n imagePickerModule: typeof ExpoImagePicker;\n documentPickerModule: typeof ExpoDocumentPicker;\n mediaLibraryModule: typeof ExpoMediaLibrary;\n fsModule: typeof ExpoFs;\n}): FileServiceInterface => {\n class ExpoFileServiceInterface implements FileServiceInterface {\n async hasCameraPermission(): Promise<boolean> {\n const res = (await imagePickerModule.getCameraPermissionsAsync()) as ExpoPermissionResponse;\n return expoPermissionGranted([res]);\n }\n async requestCameraPermission(): Promise<boolean> {\n const res = (await imagePickerModule.requestCameraPermissionsAsync()) as ExpoPermissionResponse;\n return expoPermissionGranted([res]);\n }\n async hasMediaLibraryPermission(type: 'write' | 'read'): Promise<boolean> {\n const perms = (await mediaLibraryModule.getPermissionsAsync(\n type === 'write',\n )) as ExpoMediaLibraryPermissionResponse;\n return expoPermissionGranted([perms]);\n }\n async requestMediaLibraryPermission(type: 'write' | 'read'): Promise<boolean> {\n const perms = (await mediaLibraryModule.requestPermissionsAsync(\n type === 'write',\n )) as ExpoMediaLibraryPermissionResponse;\n return expoPermissionGranted([perms]);\n }\n\n async openCamera(options?: OpenCameraOptions): Promise<FilePickerResponse> {\n const hasPermission = await this.hasCameraPermission();\n if (!hasPermission) {\n const granted = await this.requestCameraPermission();\n if (!granted) {\n options?.onOpenFailure?.(SBUError.PERMISSIONS_DENIED);\n return null;\n }\n }\n\n const response = await imagePickerModule.launchCameraAsync({\n mediaTypes: (() => {\n switch (options?.mediaType) {\n case 'photo':\n return imagePickerModule.MediaTypeOptions.Images;\n case 'video':\n return imagePickerModule.MediaTypeOptions.Videos;\n case 'all':\n return imagePickerModule.MediaTypeOptions.All;\n default:\n return imagePickerModule.MediaTypeOptions.Images;\n }\n })(),\n });\n\n if (expoBackwardUtils.toCanceled(response)) return null;\n\n const filePickerRes = await expoBackwardUtils.toFilePickerResponses(response, fsModule);\n return filePickerRes[0];\n }\n async openMediaLibrary(options: OpenMediaLibraryOptions) {\n const hasPermission = await this.hasMediaLibraryPermission('read');\n if (!hasPermission) {\n const granted = await this.requestMediaLibraryPermission('read');\n if (!granted) {\n options?.onOpenFailure?.(SBUError.PERMISSIONS_DENIED);\n return null;\n }\n }\n\n const selectionLimit = options?.selectionLimit || 1;\n const response = await imagePickerModule.launchImageLibraryAsync({\n selectionLimit,\n mediaTypes: (() => {\n switch (options?.mediaType) {\n case 'photo':\n return imagePickerModule.MediaTypeOptions.Images;\n case 'video':\n return imagePickerModule.MediaTypeOptions.Videos;\n case 'all':\n return imagePickerModule.MediaTypeOptions.All;\n default:\n return imagePickerModule.MediaTypeOptions.Images;\n }\n })(),\n });\n if (expoBackwardUtils.toCanceled(response)) return null;\n return expoBackwardUtils.toFilePickerResponses(response, fsModule);\n }\n\n async openDocument(options?: OpenDocumentOptions): Promise<FilePickerResponse> {\n try {\n const response = await documentPickerModule.getDocumentAsync({ type: '*/*' });\n if (response.type === 'cancel') return null;\n const { mimeType, uri, size, name } = response;\n return normalizeFile({ uri, size, name, type: mimeType });\n } catch (e) {\n options?.onOpenFailure?.(SBUError.UNKNOWN, e);\n return null;\n }\n }\n\n async save(options: SaveOptions): Promise<string> {\n const hasPermission = await this.hasMediaLibraryPermission('write');\n if (!hasPermission) {\n const granted = await this.requestMediaLibraryPermission('write');\n if (!granted) throw new Error('Permission not granted');\n }\n\n const basePath = fsModule.documentDirectory || fsModule.cacheDirectory;\n if (!basePath) throw new Error('Cannot determine directory');\n\n const downloadPath = `${basePath}/${options.fileName}`;\n\n const response = await fsModule.downloadAsync(options.fileUrl, downloadPath);\n if (getFileType(options.fileType || '').match(/video|image/)) {\n await mediaLibraryModule.saveToLibraryAsync(response.uri);\n }\n return response.uri;\n }\n }\n\n return new ExpoFileServiceInterface();\n};\n\nexport default createExpoFileService;\n"],"mappings":"AAKA,SAASA,WAAW,QAAQ,uBAAuB;AAEnD,OAAOC,QAAQ,MAAM,kBAAkB;AACvC,OAAOC,iBAAiB,MAAM,4BAA4B;AAE1D,OAAOC,qBAAqB,MAAM,gCAAgC;AAClE,OAAOC,aAAa,MAAM,wBAAwB;AAUlD,MAAMC,qBAAqB,GAAGC,IAAA,IAUF;EAAA,IAVG;IAC7BC,iBAAiB;IACjBC,oBAAoB;IACpBC,kBAAkB;IAClBC;EAMF,CAAC,GAAAJ,IAAA;EACC,MAAMK,wBAAwB,CAAiC;IAC7D,MAAMC,mBAAmBA,CAAA,EAAqB;MAC5C,MAAMC,GAAG,GAAI,MAAMN,iBAAiB,CAACO,yBAAyB,EAA6B;MAC3F,OAAOX,qBAAqB,CAAC,CAACU,GAAG,CAAC,CAAC;IACrC;IACA,MAAME,uBAAuBA,CAAA,EAAqB;MAChD,MAAMF,GAAG,GAAI,MAAMN,iBAAiB,CAACS,6BAA6B,EAA6B;MAC/F,OAAOb,qBAAqB,CAAC,CAACU,GAAG,CAAC,CAAC;IACrC;IACA,MAAMI,yBAAyBA,CAACC,IAAsB,EAAoB;MACxE,MAAMC,KAAK,GAAI,MAAMV,kBAAkB,CAACW,mBAAmB,CACzDF,IAAI,KAAK,OAAO,CACsB;MACxC,OAAOf,qBAAqB,CAAC,CAACgB,KAAK,CAAC,CAAC;IACvC;IACA,MAAME,6BAA6BA,CAACH,IAAsB,EAAoB;MAC5E,MAAMC,KAAK,GAAI,MAAMV,kBAAkB,CAACa,uBAAuB,CAC7DJ,IAAI,KAAK,OAAO,CACsB;MACxC,OAAOf,qBAAqB,CAAC,CAACgB,KAAK,CAAC,CAAC;IACvC;IAEA,MAAMI,UAAUA,CAACC,OAA2B,EAA+B;MACzE,MAAMC,aAAa,GAAG,MA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A,OAAOlB,QAAQ,CAACkB,GAAG;IACrB;EACF;EAEA,OAAO,IAAItC,wBAAwB,EAAE;AACvC,CAAC;AAED,eAAeN,qBAAqB"}
1
+ {"version":3,"names":["getFileType","SBUError","expoBackwardUtils","expoPermissionGranted","createExpoFileService","_ref","imagePickerModule","documentPickerModule","mediaLibraryModule","fsModule","ExpoFileServiceInterface","hasCameraPermission","res","getCameraPermissionsAsync","requestCameraPermission","requestCameraPermissionsAsync","hasMediaLibraryPermission","type","perms","getPermissionsAsync","requestMediaLibraryPermission","requestPermissionsAsync","openCamera","options","hasPermission","granted","_options$onOpenFailur","onOpenFailure","call","PERMISSIONS_DENIED","response","launchCameraAsync","mediaTypes","mediaType","MediaTypeOptions","Images","Videos","All","imagePicker","isCanceled","file","toFilePickerResponses","openMediaLibrary","_options$onOpenFailur2","selectionLimit","launchImageLibraryAsync","openDocument","getDocumentAsync","documentPicker","e","_options$onOpenFailur3","UNKNOWN","save","Error","basePath","documentDirectory","cacheDirectory","downloadPath","fileName","downloadAsync","fileUrl","fileType","match","saveToLibraryAsync","uri"],"sources":["createFileService.expo.ts"],"sourcesContent":["import type * as ExpoDocumentPicker from 'expo-document-picker';\nimport type * as ExpoFs from 'expo-file-system';\nimport type * as ExpoImagePicker from 'expo-image-picker';\nimport type * as ExpoMediaLibrary from 'expo-media-library';\n\nimport { getFileType } from '@sendbird/uikit-utils';\n\nimport SBUError from '../libs/SBUError';\nimport expoBackwardUtils from '../utils/expoBackwardUtils';\nimport type { ExpoMediaLibraryPermissionResponse, ExpoPermissionResponse } from '../utils/expoPermissionGranted';\nimport expoPermissionGranted from '../utils/expoPermissionGranted';\nimport type {\n FilePickerResponse,\n FileServiceInterface,\n OpenCameraOptions,\n OpenDocumentOptions,\n OpenMediaLibraryOptions,\n SaveOptions,\n} from './types';\n\nconst createExpoFileService = ({\n imagePickerModule,\n documentPickerModule,\n mediaLibraryModule,\n fsModule,\n}: {\n imagePickerModule: typeof ExpoImagePicker;\n documentPickerModule: typeof ExpoDocumentPicker;\n mediaLibraryModule: typeof ExpoMediaLibrary;\n fsModule: typeof ExpoFs;\n}): FileServiceInterface => {\n class ExpoFileServiceInterface implements FileServiceInterface {\n async hasCameraPermission(): Promise<boolean> {\n const res = (await imagePickerModule.getCameraPermissionsAsync()) as ExpoPermissionResponse;\n return expoPermissionGranted([res]);\n }\n async requestCameraPermission(): Promise<boolean> {\n const res = (await imagePickerModule.requestCameraPermissionsAsync()) as ExpoPermissionResponse;\n return expoPermissionGranted([res]);\n }\n async hasMediaLibraryPermission(type: 'write' | 'read'): Promise<boolean> {\n const perms = (await mediaLibraryModule.getPermissionsAsync(\n type === 'write',\n )) as ExpoMediaLibraryPermissionResponse;\n return expoPermissionGranted([perms]);\n }\n async requestMediaLibraryPermission(type: 'write' | 'read'): Promise<boolean> {\n const perms = (await mediaLibraryModule.requestPermissionsAsync(\n type === 'write',\n )) as ExpoMediaLibraryPermissionResponse;\n return expoPermissionGranted([perms]);\n }\n\n async openCamera(options?: OpenCameraOptions): Promise<FilePickerResponse> {\n const hasPermission = await this.hasCameraPermission();\n if (!hasPermission) {\n const granted = await this.requestCameraPermission();\n if (!granted) {\n options?.onOpenFailure?.(SBUError.PERMISSIONS_DENIED);\n return null;\n }\n }\n\n const response = await imagePickerModule.launchCameraAsync({\n mediaTypes: (() => {\n switch (options?.mediaType) {\n case 'photo':\n return imagePickerModule.MediaTypeOptions.Images;\n case 'video':\n return imagePickerModule.MediaTypeOptions.Videos;\n case 'all':\n return imagePickerModule.MediaTypeOptions.All;\n default:\n return imagePickerModule.MediaTypeOptions.Images;\n }\n })(),\n });\n\n if (expoBackwardUtils.imagePicker.isCanceled(response)) return null;\n\n const [file] = await expoBackwardUtils.imagePicker.toFilePickerResponses(response, fsModule);\n return file;\n }\n async openMediaLibrary(options: OpenMediaLibraryOptions) {\n const hasPermission = await this.hasMediaLibraryPermission('read');\n if (!hasPermission) {\n const granted = await this.requestMediaLibraryPermission('read');\n if (!granted) {\n options?.onOpenFailure?.(SBUError.PERMISSIONS_DENIED);\n return null;\n }\n }\n\n const selectionLimit = options?.selectionLimit || 1;\n const response = await imagePickerModule.launchImageLibraryAsync({\n selectionLimit,\n mediaTypes: (() => {\n switch (options?.mediaType) {\n case 'photo':\n return imagePickerModule.MediaTypeOptions.Images;\n case 'video':\n return imagePickerModule.MediaTypeOptions.Videos;\n case 'all':\n return imagePickerModule.MediaTypeOptions.All;\n default:\n return imagePickerModule.MediaTypeOptions.Images;\n }\n })(),\n });\n if (expoBackwardUtils.imagePicker.isCanceled(response)) return null;\n return expoBackwardUtils.imagePicker.toFilePickerResponses(response, fsModule);\n }\n\n async openDocument(options?: OpenDocumentOptions): Promise<FilePickerResponse> {\n try {\n const response = await documentPickerModule.getDocumentAsync({ type: '*/*' });\n if (expoBackwardUtils.documentPicker.isCanceled(response)) return null;\n\n const [file] = await expoBackwardUtils.documentPicker.toFilePickerResponses(response);\n return file;\n } catch (e) {\n options?.onOpenFailure?.(SBUError.UNKNOWN, e);\n return null;\n }\n }\n\n async save(options: SaveOptions): Promise<string> {\n const hasPermission = await this.hasMediaLibraryPermission('write');\n if (!hasPermission) {\n const granted = await this.requestMediaLibraryPermission('write');\n if (!granted) throw new Error('Permission not granted');\n }\n\n const basePath = fsModule.documentDirectory || fsModule.cacheDirectory;\n if (!basePath) throw new Error('Cannot determine directory');\n\n const downloadPath = `${basePath}/${options.fileName}`;\n\n const response = await fsModule.downloadAsync(options.fileUrl, downloadPath);\n if (getFileType(options.fileType || '').match(/video|image/)) {\n await mediaLibraryModule.saveToLibraryAsync(response.uri);\n }\n return response.uri;\n }\n }\n\n return new ExpoFileServiceInterface();\n};\n\nexport default createExpoFileService;\n"],"mappings":"AAKA,SAASA,WAAW,QAAQ,uBAAuB;AAEnD,OAAOC,QAAQ,MAAM,kBAAkB;AACvC,OAAOC,iBAAiB,MAAM,4BAA4B;AAE1D,OAAOC,qBAAqB,MAAM,gCAAgC;AAUlE,MAAMC,qBAAqB,GAAGC,IAAA,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AAQ,CAACkD,OAAO,EAAEF,CAAC,CAAC;QAC7C,OAAO,IAAI;MACb;IACF;IAEA,MAAMG,IAAIA,CAAC7B,OAAoB,EAAmB;MAChD,MAAMC,aAAa,GAAG,MAAM,IAAI,CAACR,yBAAyB,CAAC,OAAO,CAAC;MACnE,IAAI,CAACQ,aAAa,EAAE;QAClB,MAAMC,OAAO,GAAG,MAAM,IAAI,CAACL,6BAA6B,CAAC,OAAO,CAAC;QACjE,IAAI,CAACK,OAAO,EAAE,MAAM,IAAI4B,KAAK,CAAC,wBAAwB,CAAC;MACzD;MAEA,MAAMC,QAAQ,GAAG7C,QAAQ,CAAC8C,iBAAiB,IAAI9C,QAAQ,CAAC+C,cAAc;MACtE,IAAI,CAACF,QAAQ,EAAE,MAAM,IAAID,KAAK,CAAC,4BAA4B,CAAC;MAE5D,MAAMI,YAAY,GAAI,GAAEH,QAAS,IAAG/B,OAAO,CAACmC,QAAS,EAAC;MAEtD,MAAM5B,QAAQ,GAAG,MAAMrB,QAAQ,CAACkD,aAAa,CAACpC,OAAO,CAACqC,OAAO,EAAEH,YAAY,CAAC;MAC5E,IAAIzD,WAAW,CAACuB,OAAO,CAACsC,QAAQ,IAAI,EAAE,CAAC,CAACC,KAAK,CAAC,aAAa,CAAC,EAAE;QAC5D,MAAMtD,kBAAkB,CAACuD,kBAAkB,CAACjC,QAAQ,CAACkC,GAAG,CAAC;MAC3D;MACA,OAAOlC,QAAQ,CAACkC,GAAG;IACrB;EACF;EAEA,OAAO,IAAItD,wBAAwB,EAAE;AACvC,CAAC;AAED,eAAeN,qBAAqB"}
@@ -1,43 +1,88 @@
1
1
  import normalizeFile from './normalizeFile';
2
2
  const expoBackwardUtils = {
3
- toCanceled(result) {
4
- // @ts-expect-error backward compatibility
5
- return result.canceled ?? result.cancelled;
6
- },
7
- toFileSize(info) {
8
- if ('size' in info) {
9
- return info.size;
10
- } else {
11
- return 0;
3
+ imagePicker: {
4
+ isCanceled(result) {
5
+ // @ts-expect-error backward compatibility
6
+ return result.canceled ?? result.cancelled;
7
+ },
8
+ async toFilePickerResponses(result, fsModule) {
9
+ if (result.assets) {
10
+ const assets = result.assets || [];
11
+ const promises = assets.map(_ref => {
12
+ let {
13
+ fileName: name,
14
+ fileSize: size,
15
+ type,
16
+ uri
17
+ } = _ref;
18
+ return normalizeFile({
19
+ uri,
20
+ size,
21
+ name,
22
+ type
23
+ });
24
+ });
25
+ return Promise.all(promises);
26
+ } else if ('uri' in result && typeof result.uri === 'string') {
27
+ const fileInfo = await fsModule.getInfoAsync(result.uri);
28
+ const response = await normalizeFile({
29
+ uri: result.uri,
30
+ size: expoBackwardUtils.toFileSize(fileInfo)
31
+ });
32
+ return [response];
33
+ } else {
34
+ return [];
35
+ }
12
36
  }
13
37
  },
14
- async toFilePickerResponses(result, fsModule) {
15
- if (result.assets) {
16
- const assets = result.assets || [];
17
- const promises = assets.map(_ref => {
18
- let {
19
- fileName: name,
20
- fileSize: size,
21
- type,
22
- uri
23
- } = _ref;
24
- return normalizeFile({
38
+ documentPicker: {
39
+ isCanceled(result) {
40
+ // @ts-expect-error backward compatibility
41
+ return result.canceled ?? result.type === 'cancel';
42
+ },
43
+ async toFilePickerResponses(result) {
44
+ if (result.assets) {
45
+ const assets = result.assets || [];
46
+ const promises = assets.map(_ref2 => {
47
+ let {
48
+ name,
49
+ size,
50
+ mimeType,
51
+ uri
52
+ } = _ref2;
53
+ return normalizeFile({
54
+ uri,
55
+ size,
56
+ name,
57
+ type: mimeType
58
+ });
59
+ });
60
+ return Promise.all(promises);
61
+ } else if ('uri' in result && typeof result.uri === 'string') {
62
+ // @ts-expect-error backward compatibility
63
+ const {
64
+ mimeType,
65
+ uri,
66
+ size,
67
+ name
68
+ } = result;
69
+ const response = await normalizeFile({
25
70
  uri,
26
71
  size,
27
72
  name,
28
- type
73
+ type: mimeType
29
74
  });
30
- });
31
- return Promise.all(promises);
32
- } else if ('uri' in result && typeof result.uri === 'string') {
33
- const fileInfo = await fsModule.getInfoAsync(result.uri);
34
- const response = await normalizeFile({
35
- uri: result.uri,
36
- size: this.toFileSize(fileInfo)
37
- });
38
- return [response];
75
+ return [response];
76
+ } else {
77
+ return [];
78
+ }
79
+ }
80
+ },
81
+ toFileSize(info) {
82
+ if ('size' in info) {
83
+ return info.size;
39
84
  } else {
40
- return [];
85
+ return 0;
41
86
  }
42
87
  }
43
88
  };
@@ -1 +1 @@
1
- {"version":3,"names":["normalizeFile","expoBackwardUtils","toCanceled","result","canceled","cancelled","toFileSize","info","size","toFilePickerResponses","fsModule","assets","promises","map","_ref","fileName","name","fileSize","type","uri","Promise","all","fileInfo","getInfoAsync","response"],"sources":["expoBackwardUtils.ts"],"sourcesContent":["import type * as ExpoFs from 'expo-file-system';\nimport type * as ExpoImagePicker from 'expo-image-picker';\n\nimport type { FilePickerResponse } from '../platform/types';\nimport normalizeFile from './normalizeFile';\n\nconst expoBackwardUtils = {\n toCanceled(result: ExpoImagePicker.ImagePickerResult) {\n // @ts-expect-error backward compatibility\n return result.canceled ?? result.cancelled;\n },\n toFileSize(info: ExpoFs.FileInfo) {\n if ('size' in info) {\n return info.size;\n } else {\n return 0;\n }\n },\n async toFilePickerResponses(\n result: ExpoImagePicker.ImagePickerResult,\n fsModule: typeof ExpoFs,\n ): Promise<FilePickerResponse[]> {\n if (result.assets) {\n const assets = result.assets || [];\n const promises = assets.map(({ fileName: name, fileSize: size, type, uri }) =>\n normalizeFile({ uri, size, name, type }),\n );\n\n return Promise.all(promises);\n } else if ('uri' in result && typeof result.uri === 'string') {\n const fileInfo = await fsModule.getInfoAsync(result.uri);\n const response = await normalizeFile({ uri: result.uri, size: this.toFileSize(fileInfo) });\n return [response];\n } else {\n return [];\n }\n },\n};\n\nexport default expoBackwardUtils;\n"],"mappings":"AAIA,OAAOA,aAAa,MAAM,iBAAiB;AAE3C,MAAMC,iBAAiB,GAAG;EACxBC,UAAUA,CAACC,MAAyC,EAAE;IACpD;IACA,OAAOA,MAAM,CAACC,QAAQ,IAAID,MAAM,CAACE,SAAS;EAC5C,CAAC;EACDC,UAAUA,CAACC,IAAqB,EAAE;IAChC,IAAI,MAAM,IAAIA,IAAI,EAAE;MAClB,OAAOA,IAAI,CAACC,IAAI;IAClB,CAAC,MAAM;MACL,OAAO,CAAC;IACV;EACF,CAAC;EACD,MAAMC,qBAAqBA,CACzBN,MAAyC,EACzCO,QAAuB,EACQ;IAC/B,IAAIP,MAAM,CAACQ,MAAM,EAAE;MACjB,MAAMA,MAAM,GAAGR,MAAM,CAACQ,MAAM,IAAI,EAAE;MAClC,MAAMC,QAAQ,GAAGD,MAAM,CAACE,GAAG,CAACC,IAAA;QAAA,IAAC;UAAEC,QAAQ,EAAEC,IAAI;UAAEC,QAAQ,EAAET,IAAI;UAAEU,IAAI;UAAEC;QAAI,CAAC,GAAAL,IAAA;QAAA,OACxEd,aAAa,CAAC;UAAEmB,GAAG;UAAEX,IAAI;UAAEQ,IAAI;UAAEE;QAAK,CAAC,CAAC;MAAA,EACzC;MAED,OAAOE,OAAO,CAACC,GAAG,CAACT,QAAQ,CAAC;IAC9B,CAAC,MAAM,IAAI,KAAK,IAAIT,MAAM,IAAI,OAAOA,MAAM,CAACgB,GAAG,KAAK,QAAQ,EAAE;MAC5D,MAAMG,QAAQ,GAAG,MAAMZ,QAAQ,CAACa,YAAY,CAACpB,MAAM,CAACgB,GAAG,CAAC;MACxD,MAAMK,QAAQ,GAAG,MAAMxB,aAAa,CAAC;QAAEmB,GAAG,EAAEhB,MAAM,CAACgB,GAAG;QAAEX,IAAI,EAAE,IAAI,CAACF,UAAU,CAACgB,QAAQ;MAAE,CAAC,CAAC;MAC1F,OAAO,CAACE,QAAQ,CAAC;IACnB,CAAC,MAAM;MACL,OAAO,EAAE;IACX;EACF;AACF,CAAC;AAED,eAAevB,iBAAiB"}
1
+ {"version":3,"names":["normalizeFile","expoBackwardUtils","imagePicker","isCanceled","result","canceled","cancelled","toFilePickerResponses","fsModule","assets","promises","map","_ref","fileName","name","fileSize","size","type","uri","Promise","all","fileInfo","getInfoAsync","response","toFileSize","documentPicker","_ref2","mimeType","info"],"sources":["expoBackwardUtils.ts"],"sourcesContent":["import type * as ExpoDocumentPicker from 'expo-document-picker';\nimport type * as ExpoFs from 'expo-file-system';\nimport type * as ExpoImagePicker from 'expo-image-picker';\n\nimport type { FilePickerResponse } from '../platform/types';\nimport normalizeFile from './normalizeFile';\n\nconst expoBackwardUtils = {\n imagePicker: {\n isCanceled(result: ExpoImagePicker.ImagePickerResult) {\n // @ts-expect-error backward compatibility\n return result.canceled ?? result.cancelled;\n },\n async toFilePickerResponses(\n result: ExpoImagePicker.ImagePickerResult,\n fsModule: typeof ExpoFs,\n ): Promise<FilePickerResponse[]> {\n if (result.assets) {\n const assets = result.assets || [];\n const promises = assets.map(({ fileName: name, fileSize: size, type, uri }) =>\n normalizeFile({ uri, size, name, type }),\n );\n\n return Promise.all(promises);\n } else if ('uri' in result && typeof result.uri === 'string') {\n const fileInfo = await fsModule.getInfoAsync(result.uri);\n const response = await normalizeFile({ uri: result.uri, size: expoBackwardUtils.toFileSize(fileInfo) });\n return [response];\n } else {\n return [];\n }\n },\n },\n documentPicker: {\n isCanceled(result: ExpoDocumentPicker.DocumentPickerResult) {\n // @ts-expect-error backward compatibility\n return result.canceled ?? result.type === 'cancel';\n },\n async toFilePickerResponses(result: ExpoDocumentPicker.DocumentPickerResult): Promise<FilePickerResponse[]> {\n if (result.assets) {\n const assets = result.assets || [];\n const promises = assets.map(({ name, size, mimeType, uri }) =>\n normalizeFile({ uri, size, name, type: mimeType }),\n );\n\n return Promise.all(promises);\n } else if ('uri' in result && typeof result.uri === 'string') {\n // @ts-expect-error backward compatibility\n const { mimeType, uri, size, name } = result;\n const response = await normalizeFile({ uri, size, name, type: mimeType });\n\n return [response];\n } else {\n return [];\n }\n },\n },\n toFileSize(info: ExpoFs.FileInfo) {\n if ('size' in info) {\n return info.size;\n } else {\n return 0;\n }\n },\n};\n\nexport default expoBackwardUtils;\n"],"mappings":"AAKA,OAAOA,a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BAAqBA,CAACH,MAA+C,EAAiC;MAC1G,IAAIA,MAAM,CAACK,MAAM,EAAE;QACjB,MAAMA,MAAM,GAAGL,MAAM,CAACK,MAAM,IAAI,EAAE;QAClC,MAAMC,QAAQ,GAAGD,MAAM,CAACE,GAAG,CAACe,KAAA;UAAA,IAAC;YAAEZ,IAAI;YAAEE,IAAI;YAAEW,QAAQ;YAAET;UAAI,CAAC,GAAAQ,KAAA;UAAA,OACxD1B,aAAa,CAAC;YAAEkB,GAAG;YAAEF,IAAI;YAAEF,IAAI;YAAEG,IAAI,EAAEU;UAAS,CAAC,CAAC;QAAA,EACnD;QAED,OAAOR,OAAO,CAACC,GAAG,CAACV,QAAQ,CAAC;MAC9B,CAAC,MAAM,IAAI,KAAK,IAAIN,MAAM,IAAI,OAAOA,MAAM,CAACc,GAAG,KAAK,QAAQ,EAAE;QAC5D;QACA,MAAM;UAAES,QAAQ;UAAET,GAAG;UAAEF,IAAI;UAAEF;QAAK,CAAC,GAAGV,MAAM;QAC5C,MAAMmB,QAAQ,GAAG,MAAMvB,aAAa,CAAC;UAAEkB,GAAG;UAAEF,IAAI;UAAEF,IAAI;UAAEG,IAAI,EAAEU;QAAS,CAAC,CAAC;QAEzE,OAAO,CAACJ,QAAQ,CAAC;MACnB,CAAC,MAAM;QACL,OAAO,EAAE;MACX;IACF;EACF,CAAC;EACDC,UAAUA,CAACI,IAAqB,EAAE;IAChC,IAAI,MAAM,IAAIA,IAAI,EAAE;MAClB,OAAOA,IAAI,CAACZ,IAAI;IAClB,CAAC,MAAM;MACL,OAAO,CAAC;IACV;EACF;AACF,CAAC;AAED,eAAef,iBAAiB"}
@@ -1,3 +1,3 @@
1
- const VERSION = '3.0.3';
1
+ const VERSION = '3.0.4-rc.1';
2
2
  export default VERSION;
3
3
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["VERSION"],"sources":["version.ts"],"sourcesContent":["const VERSION = '3.0.3';\nexport default VERSION;\n"],"mappings":"AAAA,MAAMA,OAAO,GAAG,OAAO;AACvB,eAAeA,OAAO"}
1
+ {"version":3,"names":["VERSION"],"sources":["version.ts"],"sourcesContent":["const VERSION = '3.0.4-rc.1';\nexport default VERSION;\n"],"mappings":"AAAA,MAAMA,OAAO,GAAG,YAAY;AAC5B,eAAeA,OAAO"}
@@ -10,7 +10,7 @@ import type { ClipboardServiceInterface, FileServiceInterface, MediaServiceInter
10
10
  import type { ErrorBoundaryProps, LocalCacheStorage } from '../types';
11
11
  type UnimplementedFeatures = 'enableVoiceMessage' | 'threadReplySelectType' | 'replyType';
12
12
  export declare const SendbirdUIKit: Readonly<{
13
- VERSION: "3.0.3";
13
+ VERSION: "3.0.4-rc.1";
14
14
  PLATFORM: string;
15
15
  DEFAULT: {
16
16
  AUTO_PUSH_TOKEN_REGISTRATION: boolean;
@@ -1,9 +1,16 @@
1
+ import type * as ExpoDocumentPicker from 'expo-document-picker';
1
2
  import type * as ExpoFs from 'expo-file-system';
2
3
  import type * as ExpoImagePicker from 'expo-image-picker';
3
4
  import type { FilePickerResponse } from '../platform/types';
4
5
  declare const expoBackwardUtils: {
5
- toCanceled(result: ExpoImagePicker.ImagePickerResult): boolean;
6
+ imagePicker: {
7
+ isCanceled(result: ExpoImagePicker.ImagePickerResult): boolean;
8
+ toFilePickerResponses(result: ExpoImagePicker.ImagePickerResult, fsModule: typeof ExpoFs): Promise<FilePickerResponse[]>;
9
+ };
10
+ documentPicker: {
11
+ isCanceled(result: ExpoDocumentPicker.DocumentPickerResult): boolean;
12
+ toFilePickerResponses(result: ExpoDocumentPicker.DocumentPickerResult): Promise<FilePickerResponse[]>;
13
+ };
6
14
  toFileSize(info: ExpoFs.FileInfo): number;
7
- toFilePickerResponses(result: ExpoImagePicker.ImagePickerResult, fsModule: typeof ExpoFs): Promise<FilePickerResponse[]>;
8
15
  };
9
16
  export default expoBackwardUtils;
@@ -1,2 +1,2 @@
1
- declare const VERSION = "3.0.3";
1
+ declare const VERSION = "3.0.4-rc.1";
2
2
  export default VERSION;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sendbird/uikit-react-native",
3
- "version": "3.0.3",
3
+ "version": "3.0.4-rc.1",
4
4
  "description": "Sendbird UIKit for React Native: A feature-rich and customizable chat UI kit with messaging, channel management, and user authentication.",
5
5
  "keywords": [
6
6
  "sendbird",
@@ -58,10 +58,10 @@
58
58
  "access": "public"
59
59
  },
60
60
  "dependencies": {
61
- "@sendbird/uikit-chat-hooks": "3.0.3",
62
- "@sendbird/uikit-react-native-foundation": "3.0.3",
61
+ "@sendbird/uikit-chat-hooks": "3.0.4-rc.1",
62
+ "@sendbird/uikit-react-native-foundation": "3.0.4-rc.1",
63
63
  "@sendbird/uikit-tools": "^0.0.1-alpha.38",
64
- "@sendbird/uikit-utils": "3.0.3"
64
+ "@sendbird/uikit-utils": "3.0.4-rc.1"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@bam.tech/react-native-image-resizer": "^3.0.4",
@@ -77,7 +77,7 @@
77
77
  "date-fns": "^2.28.0",
78
78
  "expo-av": "^13.2.1",
79
79
  "expo-clipboard": "^4.1.2",
80
- "expo-document-picker": "^11.2.2",
80
+ "expo-document-picker": "^11.5.3",
81
81
  "expo-file-system": "^15.2.2",
82
82
  "expo-image-manipulator": "^11.1.1",
83
83
  "expo-image-picker": "^14.1.1",
@@ -203,6 +203,5 @@
203
203
  "entryPoint": "./src/index.ts",
204
204
  "readmeFile": "./README.md",
205
205
  "displayName": "@sendbird/uikit-react-native"
206
- },
207
- "gitHead": "f674e3c8280d268f4a74eb6c9cd76ea80bd57ddc"
206
+ }
208
207
  }
@@ -9,7 +9,6 @@ import SBUError from '../libs/SBUError';
9
9
  import expoBackwardUtils from '../utils/expoBackwardUtils';
10
10
  import type { ExpoMediaLibraryPermissionResponse, ExpoPermissionResponse } from '../utils/expoPermissionGranted';
11
11
  import expoPermissionGranted from '../utils/expoPermissionGranted';
12
- import normalizeFile from '../utils/normalizeFile';
13
12
  import type {
14
13
  FilePickerResponse,
15
14
  FileServiceInterface,
@@ -77,10 +76,10 @@ const createExpoFileService = ({
77
76
  })(),
78
77
  });
79
78
 
80
- if (expoBackwardUtils.toCanceled(response)) return null;
79
+ if (expoBackwardUtils.imagePicker.isCanceled(response)) return null;
81
80
 
82
- const filePickerRes = await expoBackwardUtils.toFilePickerResponses(response, fsModule);
83
- return filePickerRes[0];
81
+ const [file] = await expoBackwardUtils.imagePicker.toFilePickerResponses(response, fsModule);
82
+ return file;
84
83
  }
85
84
  async openMediaLibrary(options: OpenMediaLibraryOptions) {
86
85
  const hasPermission = await this.hasMediaLibraryPermission('read');
@@ -108,16 +107,17 @@ const createExpoFileService = ({
108
107
  }
109
108
  })(),
110
109
  });
111
- if (expoBackwardUtils.toCanceled(response)) return null;
112
- return expoBackwardUtils.toFilePickerResponses(response, fsModule);
110
+ if (expoBackwardUtils.imagePicker.isCanceled(response)) return null;
111
+ return expoBackwardUtils.imagePicker.toFilePickerResponses(response, fsModule);
113
112
  }
114
113
 
115
114
  async openDocument(options?: OpenDocumentOptions): Promise<FilePickerResponse> {
116
115
  try {
117
116
  const response = await documentPickerModule.getDocumentAsync({ type: '*/*' });
118
- if (response.type === 'cancel') return null;
119
- const { mimeType, uri, size, name } = response;
120
- return normalizeFile({ uri, size, name, type: mimeType });
117
+ if (expoBackwardUtils.documentPicker.isCanceled(response)) return null;
118
+
119
+ const [file] = await expoBackwardUtils.documentPicker.toFilePickerResponses(response);
120
+ return file;
121
121
  } catch (e) {
122
122
  options?.onOpenFailure?.(SBUError.UNKNOWN, e);
123
123
  return null;
@@ -1,3 +1,4 @@
1
+ import type * as ExpoDocumentPicker from 'expo-document-picker';
1
2
  import type * as ExpoFs from 'expo-file-system';
2
3
  import type * as ExpoImagePicker from 'expo-image-picker';
3
4
 
@@ -5,9 +6,54 @@ import type { FilePickerResponse } from '../platform/types';
5
6
  import normalizeFile from './normalizeFile';
6
7
 
7
8
  const expoBackwardUtils = {
8
- toCanceled(result: ExpoImagePicker.ImagePickerResult) {
9
- // @ts-expect-error backward compatibility
10
- return result.canceled ?? result.cancelled;
9
+ imagePicker: {
10
+ isCanceled(result: ExpoImagePicker.ImagePickerResult) {
11
+ // @ts-expect-error backward compatibility
12
+ return result.canceled ?? result.cancelled;
13
+ },
14
+ async toFilePickerResponses(
15
+ result: ExpoImagePicker.ImagePickerResult,
16
+ fsModule: typeof ExpoFs,
17
+ ): Promise<FilePickerResponse[]> {
18
+ if (result.assets) {
19
+ const assets = result.assets || [];
20
+ const promises = assets.map(({ fileName: name, fileSize: size, type, uri }) =>
21
+ normalizeFile({ uri, size, name, type }),
22
+ );
23
+
24
+ return Promise.all(promises);
25
+ } else if ('uri' in result && typeof result.uri === 'string') {
26
+ const fileInfo = await fsModule.getInfoAsync(result.uri);
27
+ const response = await normalizeFile({ uri: result.uri, size: expoBackwardUtils.toFileSize(fileInfo) });
28
+ return [response];
29
+ } else {
30
+ return [];
31
+ }
32
+ },
33
+ },
34
+ documentPicker: {
35
+ isCanceled(result: ExpoDocumentPicker.DocumentPickerResult) {
36
+ // @ts-expect-error backward compatibility
37
+ return result.canceled ?? result.type === 'cancel';
38
+ },
39
+ async toFilePickerResponses(result: ExpoDocumentPicker.DocumentPickerResult): Promise<FilePickerResponse[]> {
40
+ if (result.assets) {
41
+ const assets = result.assets || [];
42
+ const promises = assets.map(({ name, size, mimeType, uri }) =>
43
+ normalizeFile({ uri, size, name, type: mimeType }),
44
+ );
45
+
46
+ return Promise.all(promises);
47
+ } else if ('uri' in result && typeof result.uri === 'string') {
48
+ // @ts-expect-error backward compatibility
49
+ const { mimeType, uri, size, name } = result;
50
+ const response = await normalizeFile({ uri, size, name, type: mimeType });
51
+
52
+ return [response];
53
+ } else {
54
+ return [];
55
+ }
56
+ },
11
57
  },
12
58
  toFileSize(info: ExpoFs.FileInfo) {
13
59
  if ('size' in info) {
@@ -16,25 +62,6 @@ const expoBackwardUtils = {
16
62
  return 0;
17
63
  }
18
64
  },
19
- async toFilePickerResponses(
20
- result: ExpoImagePicker.ImagePickerResult,
21
- fsModule: typeof ExpoFs,
22
- ): Promise<FilePickerResponse[]> {
23
- if (result.assets) {
24
- const assets = result.assets || [];
25
- const promises = assets.map(({ fileName: name, fileSize: size, type, uri }) =>
26
- normalizeFile({ uri, size, name, type }),
27
- );
28
-
29
- return Promise.all(promises);
30
- } else if ('uri' in result && typeof result.uri === 'string') {
31
- const fileInfo = await fsModule.getInfoAsync(result.uri);
32
- const response = await normalizeFile({ uri: result.uri, size: this.toFileSize(fileInfo) });
33
- return [response];
34
- } else {
35
- return [];
36
- }
37
- },
38
65
  };
39
66
 
40
67
  export default expoBackwardUtils;
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- const VERSION = '3.0.3';
1
+ const VERSION = '3.0.4-rc.1';
2
2
  export default VERSION;